Template constraint and specializations

bearophile bearophileHUGS at lycos.com
Fri Mar 23 05:07:16 PDT 2012


Andrej Mitrovic:

> Nope. But there are simple workarounds:

Why isn't something similar to this working?

import std.traits: Unqual;

class Foo(bool feature1, bool feature2) {}

template isFoo(T) {
     static if (is(Unqual!T Unused : Foo!Features, Features...)) {
         enum isFoo = true;
     } else {
         enum isFoo = false;
     }
}

void main() {
     auto f1 = new Foo!(true, false)();
     static assert(isFoo!(typeof(f1)));
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list