Using allSatisfy with template that takes multiple type arguments

Andrej Mitrovic andrej.mitrovich at gmail.com
Tue Sep 27 13:50:36 PDT 2011


Thanks for the tips guys. I have another similar issue now, I want to
check whether a type passes any of the predicates I list. This would
be similar to anySatisfy, however anySatisfy takes one predicate and
multiple types, and what I need is one type and multiple predicates,
e.g.:

anyPredicateSatisfy!(int, isNumeric, isIntegral);

I've tried copying anySatisfy's code and modifying it to work:

template anyPredicateSatisfy(T, F...)
{
    static if (F.length == 0)
    {
        enum bool anySatisfy = false;
    }
    else static if (F.length == 1)
    {
        enum bool anySatisfy = (F[0])!T;
    }
    else
    {
        enum bool anySatisfy = (F[0])!T) || anySatisfy!(T, F[1 .. $]);
    }
}

But the compiler thinks I'm doing C-style casts so this doesn't work. Any clues?


More information about the Digitalmars-d-learn mailing list