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