www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Additional kind of template parameter: IdentifierParameter ?

Hi there,

looking at the mixin specification, it seems to me that a very useful
extension would be the introduction of a new kind of template parameter:

-------------------------------------------
template MyMember(TYPE,identifier NAME) {
        TYPE NAME;
}

class MyClass {
        mixin MyMember!(int,FooBar);
}

int main() {
        MyClass A = new MyClass;
        A.FooBar = 5;
};
-------------------------------------------

Of course, to make this really powerful, one would need some way of
manipulating identifiers, as it is possible with the C preprocessor

-------------------------------------------
template MyProperty(TYPE,identifier NAME) {
        private TYPE _ ## NAME;
        TYPE NAME() { return _ ## NAME; };
        void NAME(TYPE a) { _ ## NAME = a; };
}

class MyClass {
        mixin MyProperty!(int,FooBar);
}

int main() {
        MyClass A = new MyClass;
        A.FooBar = 5;
}
-------------------------------------------

Anyway, before deciding on a syntax for this, I would really like to have
some better understanding about the compile-time-language in general. I
believe, in the long term, there should be a way to convert between
identifiers and constant strings at compile time.
May 18 2004