File indexing completed on 2025-01-30 09:35:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_CORE_SCOPED_ENUM_HPP
0011 #define BOOST_CORE_SCOPED_ENUM_HPP
0012
0013 #include <boost/config.hpp>
0014
0015 #ifdef BOOST_HAS_PRAGMA_ONCE
0016 #pragma once
0017 #endif
0018
0019 namespace boost
0020 {
0021
0022 #ifdef BOOST_NO_CXX11_SCOPED_ENUMS
0023
0024
0025
0026
0027 template <typename EnumType>
0028 struct native_type
0029 {
0030
0031
0032
0033
0034 typedef typename EnumType::enum_type type;
0035 };
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 template <typename UnderlyingType, typename EnumType>
0046 inline
0047 BOOST_CONSTEXPR UnderlyingType underlying_cast(EnumType v) BOOST_NOEXCEPT
0048 {
0049 return v.get_underlying_value_();
0050 }
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 template <typename EnumType>
0064 inline
0065 BOOST_CONSTEXPR typename EnumType::enum_type native_value(EnumType e) BOOST_NOEXCEPT
0066 {
0067 return e.get_native_value_();
0068 }
0069
0070 #else
0071
0072 template <typename EnumType>
0073 struct native_type
0074 {
0075 typedef EnumType type;
0076 };
0077
0078 template <typename UnderlyingType, typename EnumType>
0079 inline
0080 BOOST_CONSTEXPR UnderlyingType underlying_cast(EnumType v) BOOST_NOEXCEPT
0081 {
0082 return static_cast<UnderlyingType>(v);
0083 }
0084
0085 template <typename EnumType>
0086 inline
0087 BOOST_CONSTEXPR EnumType native_value(EnumType e) BOOST_NOEXCEPT
0088 {
0089 return e;
0090 }
0091
0092 #endif
0093 }
0094
0095
0096 #ifdef BOOST_NO_CXX11_SCOPED_ENUMS
0097
0098 #ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
0099
0100 #define BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
0101 explicit BOOST_CONSTEXPR operator underlying_type() const BOOST_NOEXCEPT { return get_underlying_value_(); }
0102
0103 #else
0104
0105 #define BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR
0106
0107 #endif
0108
0109
0110
0111
0112
0113
0114
0115 #define BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(EnumType, UnderlyingType) \
0116 struct EnumType { \
0117 typedef void is_boost_scoped_enum_tag; \
0118 typedef UnderlyingType underlying_type; \
0119 EnumType() BOOST_NOEXCEPT {} \
0120 explicit BOOST_CONSTEXPR EnumType(underlying_type v) BOOST_NOEXCEPT : v_(v) {} \
0121 BOOST_CONSTEXPR underlying_type get_underlying_value_() const BOOST_NOEXCEPT { return v_; } \
0122 BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
0123 private: \
0124 underlying_type v_; \
0125 typedef EnumType self_type; \
0126 public: \
0127 enum enum_type
0128
0129 #define BOOST_SCOPED_ENUM_DECLARE_END2() \
0130 BOOST_CONSTEXPR enum_type get_native_value_() const BOOST_NOEXCEPT { return enum_type(v_); } \
0131 friend BOOST_CONSTEXPR bool operator ==(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)==enum_type(rhs.v_); } \
0132 friend BOOST_CONSTEXPR bool operator ==(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)==rhs; } \
0133 friend BOOST_CONSTEXPR bool operator ==(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs==enum_type(rhs.v_); } \
0134 friend BOOST_CONSTEXPR bool operator !=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)!=enum_type(rhs.v_); } \
0135 friend BOOST_CONSTEXPR bool operator !=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)!=rhs; } \
0136 friend BOOST_CONSTEXPR bool operator !=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs!=enum_type(rhs.v_); } \
0137 friend BOOST_CONSTEXPR bool operator <(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<enum_type(rhs.v_); } \
0138 friend BOOST_CONSTEXPR bool operator <(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<rhs; } \
0139 friend BOOST_CONSTEXPR bool operator <(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs<enum_type(rhs.v_); } \
0140 friend BOOST_CONSTEXPR bool operator <=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<=enum_type(rhs.v_); } \
0141 friend BOOST_CONSTEXPR bool operator <=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<=rhs; } \
0142 friend BOOST_CONSTEXPR bool operator <=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs<=enum_type(rhs.v_); } \
0143 friend BOOST_CONSTEXPR bool operator >(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>enum_type(rhs.v_); } \
0144 friend BOOST_CONSTEXPR bool operator >(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>rhs; } \
0145 friend BOOST_CONSTEXPR bool operator >(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs>enum_type(rhs.v_); } \
0146 friend BOOST_CONSTEXPR bool operator >=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>=enum_type(rhs.v_); } \
0147 friend BOOST_CONSTEXPR bool operator >=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>=rhs; } \
0148 friend BOOST_CONSTEXPR bool operator >=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs>=enum_type(rhs.v_); } \
0149 };
0150
0151 #define BOOST_SCOPED_ENUM_DECLARE_END(EnumType) \
0152 ; \
0153 BOOST_CONSTEXPR EnumType(enum_type v) BOOST_NOEXCEPT : v_(v) {} \
0154 BOOST_SCOPED_ENUM_DECLARE_END2()
0155
0156
0157
0158
0159
0160
0161 #define BOOST_SCOPED_ENUM_DECLARE_BEGIN(EnumType) \
0162 BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(EnumType,int)
0163
0164
0165
0166
0167
0168
0169 #define BOOST_SCOPED_ENUM_NATIVE(EnumType) EnumType::enum_type
0170
0171
0172
0173
0174
0175 #define BOOST_SCOPED_ENUM_FORWARD_DECLARE(EnumType) struct EnumType
0176
0177 #else
0178
0179 #define BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(EnumType,UnderlyingType) enum class EnumType : UnderlyingType
0180 #define BOOST_SCOPED_ENUM_DECLARE_BEGIN(EnumType) enum class EnumType
0181 #define BOOST_SCOPED_ENUM_DECLARE_END2()
0182 #define BOOST_SCOPED_ENUM_DECLARE_END(EnumType) ;
0183
0184 #define BOOST_SCOPED_ENUM_NATIVE(EnumType) EnumType
0185 #define BOOST_SCOPED_ENUM_FORWARD_DECLARE(EnumType) enum class EnumType
0186
0187 #endif
0188
0189
0190 #define BOOST_SCOPED_ENUM_START(name) BOOST_SCOPED_ENUM_DECLARE_BEGIN(name)
0191 #define BOOST_SCOPED_ENUM_END BOOST_SCOPED_ENUM_DECLARE_END2()
0192 #define BOOST_SCOPED_ENUM(name) BOOST_SCOPED_ENUM_NATIVE(name)
0193
0194 #endif