std.functional
Functions that manipulate other functions.Author:
Andrei Alexandrescu
- Transforms a string representing an expression into a unary
function. The string must use symbol name a as the parameter.
Example:
alias unaryFun!("(a & 1) == 0") isEven; assert(isEven(2) && !isEven(1));
- Transforms a string representing an expression into a Boolean binary
predicate. The string must use symbol names a and b as the
compared elements.
Example:
alias binaryFun!("a < b") less; assert(less(1, 2) && !less(2, 1)); alias binaryFun!("a > b") greater; assert(!greater("1", "2") && greater("2", "1"));
- Takes multiple functions and adjoins them together. The result is a
std.typecons.Tuple
with one element per passed-in function. Upon
invocation, the returned tuple is the adjoined results of all
functions.
Example:
static bool f1(int a) { return a != 0; } static int f2(int a) { return a / 2; } auto x = adjoin!(f1, f2)(5); assert(is(typeof(x) == Tuple!(bool, int))); assert(x._0 == true && x._1 == 2);