Template-based Preprocessing
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Tue Sep 5 07:39:27 PDT 2006
Don Clugston wrote:
> 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).
Indeed I was about to ask that too, what would be the use of such a
feature? I have to say I'm a bit skeptical, it feels way hackish.
I've read Kirk's reply about Python/C API, but it is only required there
because Python interfacing requires manipulation of object code
implementation-level semantics (the function names), as could require
any other interfacing with a C library .
But what about any actual "conceptual"/"design" use?
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list