Template constraint and specializations
Andrej Mitrovic
andrej.mitrovich at gmail.com
Fri Mar 23 01:14:05 PDT 2012
On 3/23/12, Ed McCardell <edmccard at hotmail.com> wrote:
> Is there a way to write a template constraint that matches any
> specialization of a given type?
Nope. But there are simple workarounds:
class Foo(bool feature1, bool feature2) { enum _isFoo = true; }
template isFoo(T) {
enum bool isFoo = __traits(hasMember, T, "_isFoo");
}
void useFoo(T)(T foo)
if (isFoo!T)
{
// call methods of foo that don't change based on feature1/feature2
}
void main()
{
Foo!(true, false) foo;
useFoo(foo);
}
More information about the Digitalmars-d-learn
mailing list