static code generation

js.mdnq js_adddot+mdng at gmail.com
Sun Dec 9 11:54:16 PST 2012


On Sunday, 9 December 2012 at 19:34:05 UTC, anonymous wrote:
> On Sunday, 9 December 2012 at 19:24:24 UTC, js.mdnq wrote:
>>> In this particular case you can do this:
>>> mixin template GenStruct(string stringname)
>>> {
>>>    struct S
>>>    {
>>>        ....
>>>    }
>>>    mixin("alias S " ~ stringname ~ "alpha;");
>>> }
>>
>> But what if I use more than one mixin? I'll have multiple 
>> structs
>> with the same name.
>
> That's not an issue.
>
> "If two different mixins are put in the same scope, and each 
> define a declaration with the same name, there is an ambiguity 
> error when the declaration is referenced" (note: when it's 
> referenced, not when it's declared)
> and
> "If the name of a declaration in a mixin is the same as a 
> declaration in the surrounding scope, the surrounding 
> declaration overrides the mixin one"
> - http://dlang.org/template-mixin.html


Huh?

No, I mean, if I use the mixin more than once?

GenStruct("s1");
GenStruct("s2");

then I'll have

struct s { } alias s s1;
struct s { } alias s s2;

which will fail or not be what I want, since I want to generate 
the structs s1 and s1.




More information about the Digitalmars-d-learn mailing list