2 problems I can't get my head around

Manu turkeyman at gmail.com
Mon Nov 26 05:08:48 PST 2012


On 26 November 2012 15:00, monarch_dodra <monarchdodra at gmail.com> wrote:

> 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;
> -----
>

I'm not looking for a hot-to use enums, I need to know how to form an
expression to make the pragma show true in precisely that context.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121126/1449e83a/attachment.html>


More information about the Digitalmars-d mailing list