Template-based Preprocessing

Reiner Pope reiner.pope at REMOVE.THIS.gmail.com
Wed Sep 20 05:39:10 PDT 2006


Walter Bright wrote:
> Don Clugston wrote:
>> I've previously suggested the 'identifier' keyword for string pasting.
>> Stringizing is already possible, you can find the code for 
>> symbolnameof!() in dsource/ddl/meta, together with qualifiednameof!() 
>> which is significantly more powerful than anything in C++.
>> With identifier, you'd write:
>>
>> string identifier("serialize_" ~ symbolnameof!(I))() {
>>   return toString(I);
>> }
> 
> Not a bad idea, but it would require a lot of internal rewriting of the 
> compiler to implement.
Why is implementing 'identifier' different from/harder than supporting 
the following:

template foo(char[] name)
{
    bool bar;
    static if (name == "a") alias bar a;
    static if (name == "b") alias bar b;
    static if (name == "c") alias bar c;
    ...
}

Since we can already emulate the 'identifier' keyword by doing this, 
what's the difficulty in making this supported in the compiler?

Cheers,

Reiner



More information about the Digitalmars-d mailing list