|
Boost : |
Subject: [boost] Add macros for the "enum class" concept?
From: Daryle Walker (darylew_at_[hidden])
Date: 2011-12-12 07:46:13
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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk