Using allSatisfy with template that takes multiple type arguments
bearophile
bearophileHUGS at lycos.com
Wed Sep 28 07:55:35 PDT 2011
Andrej Mitrovic:
> But the compiler thinks I'm doing C-style casts so this doesn't work. Any clues?
This seems to work (eye the base of the recursion):
template satisfies(T, alias P) { enum satisfies = P!T; }
template anyPredicateSatisfy(T, Preds...) {
static if (Preds.length)
//enum bool anyPredicateSatisfy = (Preds[0]!T) || anyPredicateSatisfy!(T, Preds[1 .. $]);
enum bool anyPredicateSatisfy = satisfies!(T, Preds[0]) || anyPredicateSatisfy!(T, Preds[1 .. $]);
else
enum bool anyPredicateSatisfy = false;
}
template is4(T) { enum is4 = T.sizeof == 4; }
template signed(T) { enum signed = T.min != 0; }
static assert(anyPredicateSatisfy!(int, is4, signed));
void main() {}
Maybe the error on (Preds[0]!T) is fodder for Bugzilla.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list