1 // scoped_enum_emulation.hpp ---------------------------------------------------------//
\r
3 // Copyright Beman Dawes, 2009
\r
5 // Distributed under the Boost Software License, Version 1.0.
\r
6 // See http://www.boost.org/LICENSE_1_0.txt
\r
8 // Generates C++0x scoped enums if the feature is present, otherwise emulates C++0x
\r
9 // scoped enums with C++03 namespaces and enums. The Boost.Config BOOST_NO_SCOPED_ENUMS
\r
10 // macro is used to detect feature support.
\r
12 // See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf for a
\r
13 // description of the scoped enum feature. Note that the committee changed the name
\r
14 // from strongly typed enum to scoped enum.
\r
16 // Caution: only the syntax is emulated; the semantics are not emulated and
\r
17 // the syntax emulation doesn't include being able to specify the underlying
\r
18 // representation type.
\r
20 // The emulation is via struct rather than namespace to allow use within classes.
\r
21 // Thanks to Andrey Semashev for pointing that out.
\r
23 // Helpful comments and suggestions were also made by Kjell Elster, Phil Endecott,
\r
24 // Joel Falcou, Mathias Gaunard, Felipe Magno de Almeida, Matt Calabrese, Vincente
\r
25 // Botet, and Daniel James.
\r
29 // BOOST_SCOPED_ENUM_START(algae) { green, red, cyan }; BOOST_SCOPED_ENUM_END
\r
31 // BOOST_SCOPED_ENUM(algae) sample( algae::red );
\r
32 // void foo( BOOST_SCOPED_ENUM(algae) color );
\r
34 // sample = algae::green;
\r
35 // foo( algae::cyan );
\r
37 #ifndef BOOST_SCOPED_ENUM_EMULATION_HPP
\r
38 #define BOOST_SCOPED_ENUM_EMULATION_HPP
\r
40 #include <boost/config.hpp>
\r
42 #ifdef BOOST_NO_SCOPED_ENUMS
\r
44 # define BOOST_SCOPED_ENUM_START(name) struct name { enum enum_t
\r
45 # define BOOST_SCOPED_ENUM_END };
\r
46 # define BOOST_SCOPED_ENUM(name) name::enum_t
\r
50 # define BOOST_SCOPED_ENUM_START(name) enum class name
\r
51 # define BOOST_SCOPED_ENUM_END
\r
52 # define BOOST_SCOPED_ENUM(name) name
\r
56 #endif // BOOST_SCOPED_ENUM_EMULATION_HPP
\r