binaryFun

Transforms a string representing an expression into a binary function. The string must either use symbol names a and b as the parameters or provide the symbols via the parm1Name and parm2Name arguments.

template binaryFun(alias fun, string parm1Name = "a", string parm2Name = "b")
static if(is(typeof(fun) : string))
binaryFun
(
ElementType1
ElementType2
)
(
auto ref ElementType1 __a
,
auto ref ElementType2 __b
)

Parameters

fun

a string or a callable

parm1Name

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

parm2Name

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

Return Value

If fun is not a string, binaryFun aliases itself away to fun.

Examples

alias less = binaryFun!("a < b");
assert(less(1, 2) && !less(2, 1));
alias greater = binaryFun!("a > b");
assert(!greater("1", "2") && greater("2", "1"));

Meta