//Purpose: // Prototype how to do: /* http://www.boost.org/libs/mpl/doc/refmanual/find-if.html */ // in d. //References: // This code is pretty much modelled after phobos' // IndexOf(T, TList...) // in: // dmd/src/phobos/std/typetuple.d // and described here: // http://www.digitalmars.com/d/phobos/std_typetuple.html // import std.typetuple; class ParamPack(TList...) { alias TList unpacked; } alias ParamPack!() empty_ppack; template FindIf(alias Predicate, PPack) { static if (PPack.unpacked.length == 0) alias PPack result_type; else static if (Predicate!(PPack.unpacked[0]).result_value) alias PPack.unpacked[0] result_type; else alias FindIf!(Predicate, ParamPack!(PPack.unpacked[1 .. length])).result_type result_type; } class TypePair(First,Second) { alias First first; alias Second second; } template FirstIs(First) { template Predicate(Pair) { static if(is(First == Pair.first)) const bool result_value=true; else const bool result_value=false; } } void test() { { alias ParamPack! ( TypePair!(int,float) , TypePair!(float,int) ) int_float_map; alias FindIf!(FirstIs!(float).Predicate,int_float_map).result_type has_float; static assert(!is(has_float == empty_ppack)); alias FindIf!(FirstIs!(int).Predicate,int_float_map).result_type has_int; static assert(!is(has_int == empty_ppack)); alias FindIf!(FirstIs!(char).Predicate,int_float_map).result_type has_char; static assert( is(has_char == empty_ppack)); } }