2 problems I can't get my head around

monarch_dodra monarchdodra at gmail.com
Mon Nov 26 05:00:40 PST 2012


On Monday, 26 November 2012 at 12:46:10 UTC, Manu wrote:
> On 26 November 2012 14:39, Andrej Mitrovic 
> <andrej.mitrovich at gmail.com>wrote:
>
>> On 11/26/12, Manu <turkeyman at gmail.com> wrote:
>> > 1.
>> >
>> > enum i = 10;
>> > pragma(msg, is(i == enum) || is(typeof(i) == enum)); // <- 
>> > false?!
>> >
>> > I can't find a way to identify that i is an enum, not a 
>> > variable; can not
>> > be assigned, has no address, etc.
>>
>> It's not an enum, it's a manifest constant.
>>
>
> Well that's certainly not intuitive. I've never even heard that 
> term
> before. It looks awfully like an enum, with the whole 'enum' 
> keyword and
> all ;)
> How do I detect that then?

The term enum (AFAIK) is comes from an old C++ hack, where you'd 
create an actual enum to represent variable that's useable 
compile-time.

Anyways, when you declare an actual enumerate, you have to 
declare:
1) The enum type
2) The enum values
3) The enum variable

So in your case, it would have to be:
--------
enum Enumerate
{
    state1 = 10,
    state2
}
Enumerate i = Enumerate.state1;
-----


More information about the Digitalmars-d mailing list