Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:40

0001 #ifndef BOOST_DESCRIBE_ENUM_HPP_INCLUDED
0002 #define BOOST_DESCRIBE_ENUM_HPP_INCLUDED
0003 
0004 // Copyright 2020 Peter Dimov
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // https://www.boost.org/LICENSE_1_0.txt
0007 
0008 #include <boost/describe/detail/config.hpp>
0009 
0010 #if !defined(BOOST_DESCRIBE_CXX14)
0011 
0012 #define BOOST_DESCRIBE_ENUM(E, ...)
0013 #define BOOST_DESCRIBE_NESTED_ENUM(E, ...)
0014 
0015 #else
0016 
0017 #include <boost/describe/detail/pp_for_each.hpp>
0018 #include <boost/describe/detail/list.hpp>
0019 #include <type_traits>
0020 
0021 namespace boost
0022 {
0023 namespace describe
0024 {
0025 namespace detail
0026 {
0027 
0028 template<class D> struct enum_descriptor
0029 {
0030     // can't use auto here because of the need to supply the definitions below
0031     static constexpr decltype(D::value()) value = D::value();
0032     static constexpr decltype(D::name()) name = D::name();
0033 };
0034 
0035 #ifndef __cpp_inline_variables
0036 // GCC requires these definitions
0037 template<class D> constexpr decltype(D::value()) enum_descriptor<D>::value;
0038 template<class D> constexpr decltype(D::name()) enum_descriptor<D>::name;
0039 #endif
0040 
0041 template<class... T> auto enum_descriptor_fn_impl( int, T... )
0042 {
0043     return list<enum_descriptor<T>...>();
0044 }
0045 
0046 #define BOOST_DESCRIBE_ENUM_BEGIN(E) \
0047     inline auto boost_enum_descriptor_fn( E** ) \
0048     { return boost::describe::detail::enum_descriptor_fn_impl( 0
0049 
0050 #define BOOST_DESCRIBE_ENUM_ENTRY(E, e) , []{ struct _boost_desc { \
0051     static constexpr auto value() noexcept { return E::e; } \
0052     static constexpr auto name() noexcept { return #e; } }; return _boost_desc(); }()
0053 
0054 #define BOOST_DESCRIBE_ENUM_END(E) ); }
0055 
0056 } // namespace detail
0057 
0058 #if defined(_MSC_VER) && !defined(__clang__)
0059 
0060 #define BOOST_DESCRIBE_ENUM(E, ...) \
0061     namespace should_use_BOOST_DESCRIBE_NESTED_ENUM {} \
0062     static_assert(std::is_enum<E>::value, "BOOST_DESCRIBE_ENUM should only be used with enums"); \
0063     BOOST_DESCRIBE_ENUM_BEGIN(E) \
0064     BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_ENUM_ENTRY, E, __VA_ARGS__) \
0065     BOOST_DESCRIBE_ENUM_END(E)
0066 
0067 #define BOOST_DESCRIBE_NESTED_ENUM(E, ...) \
0068     static_assert(std::is_enum<E>::value, "BOOST_DESCRIBE_NESTED_ENUM should only be used with enums"); \
0069     friend BOOST_DESCRIBE_ENUM_BEGIN(E) \
0070     BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_ENUM_ENTRY, E, __VA_ARGS__) \
0071     BOOST_DESCRIBE_ENUM_END(E)
0072 
0073 #else
0074 
0075 #define BOOST_DESCRIBE_ENUM(E, ...) \
0076     namespace should_use_BOOST_DESCRIBE_NESTED_ENUM {} \
0077     static_assert(std::is_enum<E>::value, "BOOST_DESCRIBE_ENUM should only be used with enums"); \
0078     BOOST_DESCRIBE_MAYBE_UNUSED BOOST_DESCRIBE_ENUM_BEGIN(E) \
0079     BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_ENUM_ENTRY, E, ##__VA_ARGS__) \
0080     BOOST_DESCRIBE_ENUM_END(E)
0081 
0082 #define BOOST_DESCRIBE_NESTED_ENUM(E, ...) \
0083     static_assert(std::is_enum<E>::value, "BOOST_DESCRIBE_NESTED_ENUM should only be used with enums"); \
0084     BOOST_DESCRIBE_MAYBE_UNUSED friend BOOST_DESCRIBE_ENUM_BEGIN(E) \
0085     BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_ENUM_ENTRY, E, ##__VA_ARGS__) \
0086     BOOST_DESCRIBE_ENUM_END(E)
0087 
0088 #endif
0089 
0090 } // namespace describe
0091 } // namespace boost
0092 
0093 #endif // defined(BOOST_DESCRIBE_CXX14)
0094 
0095 #if defined(_MSC_VER) && !defined(__clang__)
0096 
0097 #define BOOST_DEFINE_ENUM(E, ...) enum E { __VA_ARGS__ }; BOOST_DESCRIBE_ENUM(E, __VA_ARGS__)
0098 #define BOOST_DEFINE_ENUM_CLASS(E, ...) enum class E { __VA_ARGS__ }; BOOST_DESCRIBE_ENUM(E, __VA_ARGS__)
0099 
0100 #define BOOST_DEFINE_FIXED_ENUM(E, Base, ...) enum E: Base { __VA_ARGS__ }; BOOST_DESCRIBE_ENUM(E, __VA_ARGS__)
0101 #define BOOST_DEFINE_FIXED_ENUM_CLASS(E, Base, ...) enum class E: Base { __VA_ARGS__ }; BOOST_DESCRIBE_ENUM(E, __VA_ARGS__)
0102 
0103 #else
0104 
0105 #define BOOST_DEFINE_ENUM(E, ...) enum E { __VA_ARGS__ }; BOOST_DESCRIBE_ENUM(E, ##__VA_ARGS__)
0106 #define BOOST_DEFINE_ENUM_CLASS(E, ...) enum class E { __VA_ARGS__ }; BOOST_DESCRIBE_ENUM(E, ##__VA_ARGS__)
0107 
0108 #define BOOST_DEFINE_FIXED_ENUM(E, Base, ...) enum E: Base { __VA_ARGS__ }; BOOST_DESCRIBE_ENUM(E, ##__VA_ARGS__)
0109 #define BOOST_DEFINE_FIXED_ENUM_CLASS(E, Base, ...) enum class E: Base { __VA_ARGS__ }; BOOST_DESCRIBE_ENUM(E, ##__VA_ARGS__)
0110 
0111 #endif
0112 
0113 #endif // #ifndef BOOST_DESCRIBE_ENUM_HPP_INCLUDED