1 //  scoped_enum_emulation.hpp  ---------------------------------------------------------//
2 
3 //  Copyright Beman Dawes, 2009
4 
5 //  Distributed under the Boost Software License, Version 1.0.
6 //  See http://www.boost.org/LICENSE_1_0.txt
7 
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.
11 //
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.
15 //
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.
19 //
20 //  The emulation is via struct rather than namespace to allow use within classes.
21 //  Thanks to Andrey Semashev for pointing that out.
22 //
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.
26 //
27 //  Sample usage:
28 //
29 //     BOOST_SCOPED_ENUM_START(algae) { green, red, cyan }; BOOST_SCOPED_ENUM_END
30 //     ...
31 //     BOOST_SCOPED_ENUM(algae) sample( algae::red );
32 //     void foo( BOOST_SCOPED_ENUM(algae) color );
33 //     ...
34 //     sample = algae::green;
35 //     foo( algae::cyan );
36 
37 #ifndef BOOST_SCOPED_ENUM_EMULATION_HPP
38 #define BOOST_SCOPED_ENUM_EMULATION_HPP
39 
40 #include <boost/config.hpp>
41 
42 #ifdef BOOST_NO_SCOPED_ENUMS
43 
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
47 
48 #else
49 
50 # define BOOST_SCOPED_ENUM_START(name) enum class name
51 # define BOOST_SCOPED_ENUM_END
52 # define BOOST_SCOPED_ENUM(name) name
53 
54 #endif
55 
56 #endif  // BOOST_SCOPED_ENUM_EMULATION_HPP
57