static code generation

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


On Sunday, 9 December 2012 at 19:09:49 UTC, anonymous wrote:
> On Sunday, 9 December 2012 at 10:42:40 UTC, js.mdnq wrote:
>> How can I create mixes of stringified code and code itself?
> [...]
>> mixin template GenStruct(stringname)
>> {
>>     struct stringname ~ "alpha"
>>     {
>>         ....
>>     }
>> }
>>
>>
>> mixin GenStruct!("Helpme");
>>
>> would be equivalent to do the following
>>
>> struct Helpmealpha
>> {
>>    ....
>> }
>
> 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.


More information about the Digitalmars-d-learn mailing list