ddash.functional.pred

Contains types that determine the semantics of predicates

Members

Structs

eq
struct eq(alias pred)

Used to signify that pred is an equality predicate.

lt
struct lt(alias pred)

Used to signify that pred is a less than predicate

Templates

isEq
template isEq(alias pred)

Is true if pred is an eq

isLt
template isLt(alias pred)

Is true if pred is an lt

Examples

1 static struct S(alias pred) {
2     auto f(int a, int b) {
3         static if (isEq!pred) {
4             return pred(a, b);
5         } else static if (isLt!pred) {
6             return !pred(a, b) && !pred(b, a);
7         } else {
8             import std.functional: binaryFun;
9             return binaryFun!pred(a, b);
10         }
11     }
12 }
13 
14 alias A = S!(eq!((a, b) => a == b));
15 alias B = S!(lt!((a, b) => a < b));
16 
17 assert( A().f(1, 1));
18 assert( B().f(1, 1));
19 assert(!A().f(2, 1));
20 assert(!B().f(2, 1));
21 
22 static bool feq(int a, int b) { return a == b; }
23 static bool flt(int a, int b) { return a < b; }
24 
25 alias C = S!(eq!feq);
26 alias D = S!(lt!flt);
27 
28 assert( C().f(1, 1));
29 assert( D().f(1, 1));
30 assert(!C().f(1, 2));
31 assert(!D().f(1, 2));
32 
33 assert(S!"a == b"().f(1, 1));

Meta