I'd like to be able to specify a default value for a named enum, E.init, without creating a new enumeration. There are three reasons:
1) Default initializing enum variables to an "invalid" value
2) Being able to use 'final switch' without the 'init' case
3) "Invalid" init value wouldn't affect E.min or E.max

Here's what currently happens:

enum MyEnum
{
    init = -123,
    first = 0,
    second = 1
}

void main()
{
    static assert(MyEnum.min == -123);

    MyEnum me;

    final switch (me)
    {
    case MyEnum.first:  break;
    case MyEnum.second: break;
    case MyEnum.init: // I'm forced to specify init case too
    }
}

This is what I'd like to happen:

enum MyEnum
{
    init = -123,
    first = 0,
    second = 1
}

void main()
{
    static assert(MyEnum.min == 0); // no effect on min/max

    MyEnum me;

    final switch (me) // no init case necessary nor allowed
    {
    case MyEnum.first:  break;
    case MyEnum.second: break;
    }
}

Reply via email to