Using allSatisfy with template that takes multiple type arguments
Christophe
travert at phare.normalesup.org
Wed Sep 28 07:24:45 PDT 2011
Andrej Mitrovic , dans le message (digitalmars.D.learn:29825), a écrit :
> 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 .. $]);
^ you mean anyPredicateSatisfy
> }
> }
>
> 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