PhobosWatch: manifest => enum

Janice Caron caron800 at googlemail.com
Sun Dec 30 09:39:11 PST 2007


On 12/30/07, 0ffh <frank at youknow.what.todo.internetz> wrote:
> because to me the rule "case guards can only be of integral type"
> seems to make the most sense. I'd be rather disappointed if case
> one didn't work...

This bit of conversation seems to have lost track of the original
point, which, to remind all, was that Bastiaan Veelo said:

> You can regard me as a newcomer. In my view, enums are often
> used in support of switch statements. If you are loosening up
> enums so its members can be of heterogeneous types, will you
> be loosening up switch/case as well? If not, that would be
> confusing to me, as you will be able to switch on some enums
> but not on others.

So, the answer is that anonymous enums don't create new types. The
type is simply the underlying type. In the case of heterogenous
anonymous enums, the type of each element can be different.

This is a very different kettle of fish from /named/ enums, which do,
in fact, create a new type, allowing the compiler to look at code like

    enum Primary { red, green, blue }
    Primary x = whatever;
    switch (x)
    {
        case Primary.red: /*...*/
        case Primary.green: /*...*/
    }

and detect that case blue is missing, and hence a default is needed.
It cannot do that for anonymous enums, because it has no way to figure
out what the complete set should be.

At least, I /think/ that's what Bastiaan was getting at.

Anyway, the point is that the new extensions make no difference to switch/case.



More information about the Digitalmars-d mailing list