Module ddash.functional.pred
Contains types that determine the semantics of predicates
Example
static struct S(alias pred) {
auto f(int a, int b) {
static if (isEq!pred) {
return pred(a, b);
} else static if (isLt!pred) {
return !pred(a, b) && !pred(b, a);
} else {
import std.functional: binaryFun;
return binaryFun!pred(a, b);
}
}
}
alias A = S!(eq!((a, b) => a == b));
alias B = S!(lt!((a, b) => a < b));
assert( A().f(1, 1));
assert( B().f(1, 1));
assert(!A().f(2, 1));
assert(!B().f(2, 1));
static bool feq(int a, int b) { return a == b; }
static bool flt(int a, int b) { return a < b; }
alias C = S!(eq!feq);
alias D = S!(lt!flt);
assert( C().f(1, 1));
assert( D().f(1, 1));
assert(!C().f(1, 2));
assert(!D().f(1, 2));
assert(S!"a == b"().f(1, 1));
Structs
Name | Description |
eq
|
Used to signify that pred is an equality predicate.
|
lt
|
Used to signify that pred is a less than predicate
|
Manifest constants
Name | Type | Description |
isEq
|
|
Is true if pred is an eq
|
isLt
|
|
Is true if pred is an lt
|