On Saturday, 6 January 2018 at 22:25:48 UTC, ag0aep6g wrote:
On Saturday, 6 January 2018 at 19:58:10 UTC, Alex wrote:
----
template T(alias S)
{
    struct T
    {
        this(int dummy)
        {
static assert(__traits(isSame, TemplateOf!(T!arr), T));
        }
    }
}
----

Now it's a bit more obvious why the assert fails. At the location of the assert, `T` refers to the struct, not the template. To refer to the template, you can prepend a dot, which means that the lookup is done at the module level instead of searching upwards from the local level [1]. Like so:

----
static assert(__traits(isSame, TemplateOf!(.T!arr), .T));
----

You don't actually need the dot with `T!arr`. The compiler is apparently smart enough to figure out that you mean the template in that case. But it doesn't hurt, either.


[1] https://dlang.org/spec/module.html#module_scope_operators

Ah... thanks!
I chose the other way round, and compare typeof(this) directly now. My false reasoning was, that template parameters are merged to the type before analyzing the types itself.

Reply via email to