Detecting value parameter of template instance in "is" expression

Philippe Sigaud philippe.sigaud at gmail.com
Thu Dec 5 21:54:24 PST 2013


On Fri, Dec 6, 2013 at 5:31 AM, Uranuz <neuranuz at gmail.com> wrote:
> As far as I understand TemplateParamList in *is* expr should work just like
> it works in usual template. So this problem is just lack of implementation.
> I'll try to find workaround with * is( N == Nullable!(T), T ... ) * syntax.
>
> Thank you for response.

Once you are 'inside' a static if guarded by an is() expression, the
symbols you introduced inside the is() are visible, so you can test
T... further if you want. In my proposal, nV is visible right after
the is(), so here is a more correct expression:

import std.stdio, std.typecons;

template isStdNullable(N)
{
        static if(
                is( N == Nullable!(T), T )
                || is( N == NullableRef!(T), T )
                || is( N == Nullable!(T, nV), T, alias nV ) &&
is(typeof(nV) == T) // <-- There
        )
                enum bool isStdNullable = true;
        else
                enum bool isStdNullable = false;
}


void main()
{
        writeln(isStdNullable!(Nullable!(int, 10)));
}


More information about the Digitalmars-d-learn mailing list