www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - mutable compile-time data proposal

This is something I was thinking about for a long time now.

There seems to be absolutely no difference between T, const(T) and
immutable(T) if T is a compile-time value (a enum or a local in CTFE).
The possibility to mutate compile-time values (at compile time, of
course) would allow very convenient techniques to be used for a number
of purposes.
And since in my hypothetical D compile-time data can be mutated, then
a compile-time static this is required (especially for the next
For instance, here's something I'd love to be able to do:

class Base
    mixin template Register()
        ctStaticThis() // a placeholder for the real compile-time static this
                Derived = TypeTuple!(Derived, typeof(this));

    enum Derived = TypeTuple!();

class Derived1: Base
    mixin Register;

class Derived2: Base
    mixin Register;

static assert(is(Base.Derived == TypeTuple!(Base, Derived1, Derived2)));

Similar things would allow to quickly build extremely powerful and
useful compile-time information, which is currently not possible to
If mutable compile-time data is implemented, the entire compile-time
computation in D would become just like the run-time one.

Gor Gyolchanyan.
Dec 28 2011