//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; alias TypeTuple!() empty_tuple; class ParamPack(TList...) { alias TList unpacked; } template FindIf(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() { float a_float; alias ParamPack! ( TypePair!(int,float) , TypePair!(float,int) ) int_float_tuple; alias FirstIs!(float).Predicate first_is_float; alias FindIf!(first_is_float,int_float_tuple).result_type expect_yes; static assert(expect_yes != empty_tuple); }