Template-based Preprocessing

Don Clugston dac at nospam.com.au
Mon Sep 4 12:14:05 PDT 2006


Garett Bass 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++.
> 
> Thanks, Don!  I now recall your suggestion from a thread I prompted 
> about a year ago.  I've updated my example to use your suggested 
> 'identifier' keyword, as this obviates the need for my suggested 'token' 
> keyword:
> 
>    template Serializable(T, char[] I) {
>        T identifier(I);
>           string identifier("serialize_" ~ I)() {
>            return toString(identifier(I));
>        }
>    }
> 
>    class Foo {
>        mixin Serializable!(int, "i");
>    }
> 
> Foo should expand to the equivalent of:
> 
>    class Foo {
>        int i;
> 
>        string serialize_i() {
>            return toString(i);
>        }
>    }
> 
> Do you have any idea what's involved in implementing the 'identifier' 
> keyword as described here?

I don't know. It's clearly easy to get through the syntactic pass. But 
does it cause problems during name lookup?

More importantly, would it encourage bad coding styles? IMHO, it needs 
some convincing use cases -- or, if Walter gets more experimental 
post-1.0, this would be an extremely cool thing to try out. (It would 
kill one of the last metaprogramming things C++ still has compared to D).



More information about the Digitalmars-d mailing list