Template constraint and specializations

Ed McCardell edmccard at hotmail.com
Fri Mar 23 00:39:47 PDT 2012


Is there a way to write a template constraint that matches any 
specialization of a given type?

For example can the following be done without having to write out every 
combination of feature1 and feature2:

   class Foo(bool feature1, bool feature2) { ... }

   void useFoo(T)(T foo)
   if (is(T == Foo!(false, false)) || is(T == Foo!(false, true)) ||
       is(T == Foo!(true, false)) || is(T == Foo!(true, true)))
   {
      // call methods of foo that don't change based on feature1/feature2
   }

Thanks,

--Ed


More information about the Digitalmars-d-learn mailing list