Template-based Preprocessing

Georg Wrede georg.wrede at nospam.org
Sat Sep 23 01:04:55 PDT 2006


Reiner Pope wrote:
> 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?

Because in the above code the identifiers a,b,c do exist right from the 
start, whereas with the identifier suggestion they'd be "born" at a 
later stage of processing, and this means grafting them late into the 
compiler data structures.



More information about the Digitalmars-d mailing list