Cannot access template name from within template

Michael Coulombe via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 3 19:22:37 PDT 2016


On Tuesday, 4 October 2016 at 00:40:08 UTC, Andrei Alexandrescu 
wrote:
> On 10/03/2016 06:32 PM, Stefan Koch wrote:
>> On Monday, 3 October 2016 at 22:28:46 UTC, Andrei Alexandrescu 
>> wrote:
>>> Consider:
>>>
>>> template SomethingCool(alias X) { alias Y = X!int; }
>>>
>>> struct MyStruct(T) {
>>>     alias A = SomethingCool!MyStruct;
>>> }
>>>
>>> Inside MyStruct though, a mention of the symbol MyStruct 
>>> alone is
>>> actually the current instantiation - i.e. a type, not a 
>>> template.
>>>
>>> Any known workaround?
>>>
>>>
>>> Thanks,
>>>
>>> Andrei
>>
>> try defining an alias to template name outside of the template 
>> and use
>> that.
>> No guarantees.
>
> Using std.traits.TemplateOf!MyStruct works like a charm. -- 
> Andrei

You can also just do something like this, to search the 
upper/global scope:

     alias A = SomethingCool!(.MyStruct);


More information about the Digitalmars-d mailing list