Template-based Preprocessing

Garett Bass garettbass at studiotekne.com
Mon Sep 4 10:04:22 PDT 2006


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?

Regards,
Garett



More information about the Digitalmars-d mailing list