Templates and stringof...

Timon Gehr timon.gehr at gmx.ch
Sat Aug 4 06:04:42 PDT 2012


On 08/04/2012 01:35 PM, Philippe Sigaud wrote:
> On Sat, Aug 4, 2012 at 10:53 AM, David Nadlinger<see at klickverbot.at>  wrote:
>
>> example:
>>
>> ---
>> mixin template BitfieldsOn(alias target,<…>) if
>> (isIntegral!(typeof(target))) {
>>      mixin({
>>          string code;
>>          // Generate code using "target" as identifier.
>>          return code;
>>      }());
>> }
>>
>> mixin BitfieldsOn!(foo,<…>);
>> ---
>
> Yes, I recently rediscovered this trick of having a mixin integrate an
> anonymous delegate where code-as-string is generated. This is a very
> nice interaction between different parts of D. This should be
> explained somewhere, as it's a tool anyone using templates to do
> metaprogramming should be aware of.
>

http://d.puremagic.com/issues/show_bug.cgi?id=7653




More information about the Digitalmars-d mailing list