Add macros for the "enum class" concept?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Add macros for the "enum class" concept?

Daryle Walker

Should we add preprocessor stuff to conditionally use the C++11 "enum class" construct?

#if Whatever
#define BOOST_HAVE_ENUM_CLASS
#endif

//...

#if BOOST_HAVE_ENUM_CLASS
#define BOOST_ENUM_CLASS( Name )  enum class Name
#define BOOST_ENUM_CLASS_BASE( Name, Type )  enum class Name : Type
#define BOOST_ENUM_CLASS_REFER( Type, Enumerator )  (Type :: Enumerator)
#else
#define BOOST_ENUM_CLASS( Name )  enum Name
#define BOOST_ENUM_CLASS_BASE( Name, Type )  BOOST_ENUM_CLASS( Name )
#define BOOST_ENUM_CLASS_REFER( Type, Enumerator )  (Enumerator)
#endif

I'm not sure that the second version of BOOST_ENUM_CLASS_BASE is the best alternative.  Nor do I know if the parentheses around enumerators are best.

You can use BOOST_ENUM_CLASS in an enum definition header and BOOST_ENUM_CLASS_BASE as a header or a forward declaration.  Since enumerators can be scoped, BOOST_ENUM_CLASS_REFER encapsulates the need to add the enum type's name.

     

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Add macros for the "enum class" concept?

Daniel James-3
On 12 December 2011 12:46, Daryle Walker <[hidden email]> wrote:
>
> Should we add preprocessor stuff to conditionally use the C++11 "enum class" construct?

We have something like that already:

http://www.boost.org/boost/detail/scoped_enum_emulation.hpp

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Add macros for the "enum class" concept?

Daryle Walker

> Date: Mon, 12 Dec 2011 12:55:33 +0000
> From: [hidden email]

> On 12 December 2011 12:46, Daryle Walker <[hidden email]> wrote:
> >
> > Should we add preprocessor stuff to conditionally use the C++11 "enum class" construct?
>
> We have something like that already:
>
> http://www.boost.org/boost/detail/scoped_enum_emulation.hpp

Reading it, it doesn't have any base type and/or forward-declaration facilities.

     

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Add macros for the "enum class" concept?

Vicente Botet
Daryle Walker wrote
> Date: Mon, 12 Dec 2011 12:55:33 +0000
> From: [hidden email]

> On 12 December 2011 12:46, Daryle Walker <[hidden email]> wrote:
> >
> > Should we add preprocessor stuff to conditionally use the C++11 "enum class" construct?
>
> We have something like that already:
>
> http://www.boost.org/boost/detail/scoped_enum_emulation.hpp

Reading it, it doesn't have any base type and/or forward-declaration facilities.
How do you want to be able to use forward declaration in a portable way?

There are also scoped enums with underlying type that are no enum class. These could be added as well.

Vicente
Reply | Threaded
Open this post in threaded view
|

Re: Add macros for the "enum class" concept?

Vicente Botet
Vicente Botet wrote
Daryle Walker wrote
> Date: Mon, 12 Dec 2011 12:55:33 +0000
> From: [hidden email]

> On 12 December 2011 12:46, Daryle Walker <[hidden email]> wrote:
> >
> > Should we add preprocessor stuff to conditionally use the C++11 "enum class" construct?
>
> We have something like that already:
>
> http://www.boost.org/boost/detail/scoped_enum_emulation.hpp

Reading it, it doesn't have any base type and/or forward-declaration facilities.
How do you want to be able to use forward declaration in a portable way?

There are also scoped enums with underlying type that are no enum class. These could be added as well.
How do you think we can use scoped enum with underlying types in a portable way? I guess the use that states that an enum is a char expect the sizeof this enum to be the same as the sizeof char, isn't it?

I have been working a little bit on a enums library that provides such a feature (see https://svn.boost.org/svn/boost/sandbox/enums/libs/enums/doc/html/index.html). Let me know if you are interested.

Vicente



Vicente
Reply | Threaded
Open this post in threaded view
|

Re: Add macros for the "enum class" concept?

Dave Abrahams
In reply to this post by Vicente Botet

on Mon Dec 12 2011, Vicente Botet <vicente.botet-AT-wanadoo.fr> wrote:

> Daryle Walker wrote
>>
>
>>> Date: Mon, 12 Dec 2011 12:55:33 +0000
>>> From: dnljms@
>>
>>> On 12 December 2011 12:46, Daryle Walker &lt;darylew@&gt; wrote:
>>> >
>>> > Should we add preprocessor stuff to conditionally use the C++11 "enum
>>> class" construct?
>>>
>>> We have something like that already:
>>>
>>> http://www.boost.org/boost/detail/scoped_enum_emulation.hpp
>>
>> Reading it, it doesn't have any base type and/or forward-declaration
>> facilities.
>>
>>
>
> How do you want to be able to use forward declaration in a portable way?
>
> There are also scoped enums with underlying type that are no enum class.

Not in C++11.  There are unscoped enums with underlying type, but the
way you get scoping is to use "enum class."

--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Add macros for the "enum class" concept?

Vicente Botet
Dave Abrahams wrote
on Mon Dec 12 2011, Vicente Botet <vicente.botet-AT-wanadoo.fr> wrote:

> Daryle Walker wrote
>>
>
>>> Date: Mon, 12 Dec 2011 12:55:33 +0000
>>> From: dnljms@
>>
>>> On 12 December 2011 12:46, Daryle Walker <darylew@> wrote:
>>> >
>>> > Should we add preprocessor stuff to conditionally use the C++11 "enum
>>> class" construct?
>>>
>>> We have something like that already:
>>>
>>> http://www.boost.org/boost/detail/scoped_enum_emulation.hpp
>>
>> Reading it, it doesn't have any base type and/or forward-declaration
>> facilities.
>>
>>
>
> How do you want to be able to use forward declaration in a portable way?
>
> There are also scoped enums with underlying type that are no enum class.

Not in C++11.  There are unscoped enums with underlying type, but the
way you get scoping is to use "enum class."
You are right. I don't know why I thought that there was the possibility to declare an scoped enum that has implicit conversion to the underlying type. My bad.

IMO scope and convertibility are orthogonal. Do you know why this combination was not retained?

Thanks,
Vicente
Reply | Threaded
Open this post in threaded view
|

Re: Add macros for the "enum class" concept?

Dave Abrahams

on Thu Dec 15 2011, Vicente Botet <vicente.botet-AT-wanadoo.fr> wrote:

> IMO scope and convertibility are orthogonal. Do you know why this
> combination was not retained?

I'm afraid that I don't even understand your question... but even if I
did, I'm pretty sure I wouldn't know the answer.

--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Add macros for the "enum class" concept?

Vicente Botet
Le 17/12/11 23:12, Dave Abrahams a écrit :
> on Thu Dec 15 2011, Vicente Botet<vicente.botet-AT-wanadoo.fr>  wrote:
>
>> IMO scope and convertibility are orthogonal. Do you know why this
>> combination was not retained?
> I'm afraid that I don't even understand your question... but even if I
> did, I'm pretty sure I wouldn't know the answer.
>
Why C++11 doesn't supports scoped enums with underlying type that are
implicitly convertible to the underlying type?

Vicente

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Add macros for the "enum class" concept?

Dave Abrahams

on Sun Dec 18 2011, "Vicente J. Botet Escriba" <vicente.botet-AT-wanadoo.fr> wrote:

> Le 17/12/11 23:12, Dave Abrahams a écrit :
>> on Thu Dec 15 2011, Vicente Botet<vicente.botet-AT-wanadoo.fr>  wrote:
>
>>
>>> IMO scope and convertibility are orthogonal. Do you know why this
>>> combination was not retained?
>> I'm afraid that I don't even understand your question... but even if I
>> did, I'm pretty sure I wouldn't know the answer.
>>
> Why C++11 doesn't supports scoped enums with underlying type that are
> implicitly convertible to the underlying type?

You're asking the wrong guy.  I suggest finding out who wrote the
standard proposals (you can find the paper and credits at
http://open-std.org).

--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost