Template bind

Allows you to bind arguments to a function at different positions

template bind(alias pred, BoundArgs...) ;

E.g. bind arguments to the 1st and 3rd parameter and call:

void f(int a, int b, int c) {}
alias a = bind!(f, 1, void, 3);
alias b = (int second) => f(1, second, 3);

a(2); // calls f(1, 2, 3);
b(2); // calls f(1, 2, 3);

Contained Functions

NameDescription
bind

Parameters

NameDescription
pred the predicate to bind arguments to
BoundArgs the arguments to bind. Use void to leave an argument slot open

See Also

std.functional.partial

Since

0.9.0

Example

auto f0(int a, int b, int c) {
    return a * b + c;
}

assert(bind!(f0, 2, 3, 4)() == 10);
assert(bind!(f0, 2, void, 4)(3) == 10);
assert(bind!(f0, 2, void, void)(3, 4) == 10);
assert(bind!(f0, void, void, void)(2, 3, 4) == 10);
assert(bind!(f0, void, void, 4)(2, 3) == 10);
assert(bind!(f0, void, 3, 4)(2) == 10);