1 module beard.find;
2 public import beard.type_list : TL;
3 public import beard.fold_left : foldLeft;
4 public import beard.inverse : inverse;
5 
6 /// Returns the first type for which C!T returns true, else return void.
7 template find(alias C, T...) {
8     static if (! T.length)
9         alias void find;
10     else static if (C!(T[0]))
11         alias T[0] find;
12     else
13         alias find!(C, T[1..$]) find;
14 }
15 
16 /// Return all the types for which C!T returns true.
17 template findAll(alias C, T...) {
18     template fold(alias R, U) {
19         static if (C!U)
20             alias R.append!U fold;
21         else
22             alias R fold;
23     }
24 
25     alias foldLeft!(fold, TL!(), T).types findAll;
26 }
27 
28 /// Return all the types for which C!T returns false.
29 template filter(alias C, T...) {
30     alias findAll!(inverse!C, T) filter;
31 }
32 // vim:ts=4 sw=4