You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The simple way of making a normal function definition dependant on some sort of condition is to wrap it inside an #if
#if defined WIN32 {
def foo -> int { return 10 }
}
However, for generic functions it isn't so simple. There is currently no way to "enable" a function if a condition is met.
Take index_of from Vector as an example:
export def index_of(vec: &Vector(type T), elem: T) -> int64 {
for var i in 0..vec.length {
if vec[i] == elem {
return i
}
}
return -1
}
This function only makes sense if equality is defined between element types.
Now there's certainly the option to codify this condition with a type, possibly using this syntax:
The simple way of making a normal function definition dependant on some sort of condition is to wrap it inside an
#if
However, for generic functions it isn't so simple. There is currently no way to "enable" a function if a condition is met.
Take
index_of
from Vector as an example:This function only makes sense if equality is defined between element types.
Now there's certainly the option to codify this condition with a type, possibly using this syntax:
However more complex conditions can't be expressed in that way.
My idea is to wrap the function body in an
#if
statement like this:The text was updated successfully, but these errors were encountered: