Template constraint and specializations
Ed McCardell
edmccard at hotmail.com
Fri Mar 23 02:17:18 PDT 2012
On 03/23/2012 04:14 AM, Andrej Mitrovic wrote:
> 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");
> }
Thanks! I was tempted to try something hacky for the constraint, like
if (T.stringof == "Foo")
but tagging the type with an enum works better all around.
--Ed
More information about the Digitalmars-d-learn
mailing list