On Tuesday, 11 June 2013 at 19:52:01 UTC, Seany wrote:
Hello

i read here that enums, once initialized, are constants :
http://ddili.org/ders/d.en/enum.html

However, i need a method, if possible, to dynamically (cexecution time) definition of enums, and updating them.

anyidea how that can be done? using const and/or inout, and passing an array / tuple to a function?

You could..., but it'd be nothing more than a glorified global struct.

Inside a module, I'd put this:

//----
private struct Enum
{
    static
    {
        public @property const
        {
            uint a(){return _a;}
            uint b(){return _b;}
            uint c(){return _c;}
        }

        private
        {
            uint _a = 0;
            uint _b = 1;
            uint _c = 2;
        }
    }
}

void changeState()
{
    Enum._a = 2;
    Enum._c = 0;
}
//----

Then you can use it...
void main()
{
    writeln(Enum.a);
    writeln(Enum.c);
    changeState();
    writeln(Enum.a);
    writeln(Enum.c);
}

But even then, keep i mind these aren't compile time objects, so you can't use them in a switch, for example...

Reply via email to