The OpenD Programming Language

unaryFun

Transforms a string representing an expression into a unary function. The string must either use symbol name a as the parameter or provide the symbol via the parmName argument.

template unaryFun(alias fun, string parmName = "a")
static if(is(typeof(fun) : string))
unaryFun
(
ElementType
)
(
auto ref ElementType __a
)

Parameters

fun

a string or a callable

parmName

the name of the parameter if fun is a string. Defaults to "a".

Return Value

If fun is a string, a new single parameter function

If fun is not a string, an alias to fun.

Examples

// Strings are compiled into functions:
alias isEven = unaryFun!("(a & 1) == 0");
assert(isEven(2) && !isEven(1));

Meta