Boost logo

Boost :

Subject: Re: [boost] [C++0x] Emulation of scoped enums
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-03-06 12:18:16


----- Original Message -----
From: "Daniel James" <daniel_james_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, March 06, 2009 12:39 PM
Subject: Re: [boost] [C++0x] Emulation of scoped enums

>
> 2009/3/6 vicente.botet <vicente.botet_at_[hidden]>:
>>
>> I don't think there is a better solution. You need to mask the fact that a enum type in C++0x is name scope and a type and can not be in C++03.
>
> A class is a name scope and a type - isn't that why it's called 'enum class'?
>
> class algae {
> public:
> enum value {green, red, cyan};
>
> algae() {}
> algae(value v) : v_(v) {}
>
> // And any other required methods...
> private:
> value v_;
> };
>
> algae x = algae::red;
> algae y = red; // error...
>
> This would also be closer to 'enum class' as it's strongly typed.
>
> Beman's preprocessing syntax would have to change, as the closing
> macro would have to know the name. The syntax using a preprocessor
> sequence or varargs would be the same.

Hi,

The generated code of the macro can generate this or what Beman proposed. In any case the _START, _END will be needed.

I like your solution because it allows to create a different type. I think that in addition it would be great to allows the storage type to be an integer type other that the enum value (emulation of the enum_base)

In order to recall as much as possible the C++0X syntax

enum class algae {green, red, cyan };
enum class mycolors : unsigned char {green, red, cyan };

what about

   BOOST_ENUM_CLASS_START(algae) { green, red, cyan };
   BOOST_ENUM_CLASS_END

   BOOST_GENERIC_ENUM_CLASS_START(algae, unsigned char) { green, red, cyan };
   BOOST_ENUM_CLASS_END

And use BOOST_ENUM_CLASS(algae)?

Best,
Vicente

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk