Using template mixin, with or without mixin ?

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 8 22:44:21 PDT 2017


On Saturday, 8 April 2017 at 22:37:18 UTC, ag0aep6g wrote:
> On 04/08/2017 11:59 PM, Meta wrote:
>> enum a = 0;
>>
>> template test1()
>> {
>>     enum b1 = a; //Okay, a is in scope at the declaration site
>>     //enum c = d1; Error: undefined identifier d1
>
> This line works just fine, actually. There's really no 
> difference between a normal template and a mixin template when 
> you use it in a mixin.
>
>> }
>>
>> mixin template test2()
>> {
>>     enum b2 = a; //Okay, a is in scope at the declaration site
>>     enum c = d1; //Okay, d1 is in scope at the *instantiation* 
>> site
>>     //enum e = d2; Error: undefined identifier d2
>> }
>>
>> void main()
>> {
>>     enum d1 = 0; //<--d1 is declared here
>>     mixin test1!();
>>     mixin test2!(); //<--so it is in scope here
>>     enum d2 = 0; //d2 was not declared before test2 was mixed 
>> in
>>                      //so it is not in scope for test2
>> }

Hmm, you're right, but this is not how it is supposed to behave 
according to the documentation.

https://dlang.org/spec/template-mixin.html


More information about the Digitalmars-d-learn mailing list