reverseArgs

N-ary predicate that reverses the order of arguments, e.g., given pred(a, b, c), returns pred(c, b, a).

template reverseArgs(alias pred)
reverseArgs
(
Args...
)
(
auto ref Args args
)
if (
is(typeof(pred(Reverse!args)))
)

Parameters

pred

A callable

Return Value

A function which calls pred after reversing the given parameters

Examples

alias gt = reverseArgs!(binaryFun!("a < b"));
assert(gt(2, 1) && !gt(1, 1));
int x = 42;
bool xyz(int a, int b) { return a * x < b / x; }
auto foo = &xyz;
foo(4, 5);
alias zyx = reverseArgs!(foo);
assert(zyx(5, 4) == foo(4, 5));
alias gt = reverseArgs!(binaryFun!("a < b"));
assert(gt(2, 1) && !gt(1, 1));
int x = 42;
bool xyz(int a, int b) { return a * x < b / x; }
auto foo = &xyz;
foo(4, 5);
alias zyx = reverseArgs!(foo);
assert(zyx(5, 4) == foo(4, 5));
int abc(int a, int b, int c) { return a * b + c; }
alias cba = reverseArgs!abc;
assert(abc(91, 17, 32) == cba(32, 17, 91));
int a(int a) { return a * 2; }
alias _a = reverseArgs!a;
assert(a(2) == _a(2));
int b() { return 4; }
alias _b = reverseArgs!b;
assert(b() == _b());

Meta