Check whether a type is a instantiated by a template struct
Jakob Ovrum
jakobovrum at gmail.com
Sat Aug 11 12:30:29 PDT 2012
On Saturday, 11 August 2012 at 19:06:22 UTC, Chris Cain wrote:
> Same idea, but doing it with just one template and using static
> ifs...
>
> struct S(T) {}
>
> template isS(T) {
> static if(is(T _ : S!U, U))
> enum isS = true;
> else
> enum isS = false;
> }
>
> static assert(isS!(S!float));
> static assert(!isS!float);
I usually prefer overloading for this particular kind of template
because of the restriction that is() expressions may only
introduce symbols when used in static-if statements. I think the
if(blah) a = true; else a = false; pattern is worth avoiding as
it leaves a bad taste in the mouth of many programmers.
More information about the Digitalmars-d-learn
mailing list