PhobosWatch: manifest => enum

Derek Parnell derek at psych.ward
Sun Dec 30 04:09:47 PST 2007


On Sun, 30 Dec 2007 11:27:17 +0000, Janice Caron wrote:

> On 12/30/07, Bastiaan Veelo <Bastiaan at veelo.net> wrote:
>> If not, that would be confusing to me, as you will
>> be able to switch on some enums but not on others.
> 
> You can't switch on an anonymous enum. Anonymous enums have no type,
> and therefore it is not even /possible/ to generate an expression
> whose type is that of an anonymous enum!
> 
> So switch/case survives unharmed.

And yet this compiles and runs ...

// -------------
import std.stdio;

enum
{
one = 1,
two = 2,
three = 3
}

void main()
{
    auto x = three;
   
    switch (x)
    {
        case one: writefln("ONE"); break;
        case two: writefln("TWO"); break;
        case three: writefln("THREE"); break;
    }
}     
// -------------

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list