mirror of
https://github.com/boostorg/core.git
synced 2025-07-30 04:47:24 +02:00
-Added constexpr and noexcept specifiers to make the emulation technically closer to the actual enums.
This commit is contained in:
@ -43,7 +43,8 @@ namespace boost
|
|||||||
* @throws No-throws.
|
* @throws No-throws.
|
||||||
*/
|
*/
|
||||||
template <typename UnderlyingType, typename EnumType>
|
template <typename UnderlyingType, typename EnumType>
|
||||||
UnderlyingType underlying_cast(EnumType v)
|
inline
|
||||||
|
BOOST_CONSTEXPR UnderlyingType underlying_cast(EnumType v) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return v.get_underlying_value_();
|
return v.get_underlying_value_();
|
||||||
}
|
}
|
||||||
@ -61,7 +62,7 @@ namespace boost
|
|||||||
*/
|
*/
|
||||||
template <typename EnumType>
|
template <typename EnumType>
|
||||||
inline
|
inline
|
||||||
typename EnumType::enum_type native_value(EnumType e)
|
BOOST_CONSTEXPR typename EnumType::enum_type native_value(EnumType e) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return e.get_native_value_();
|
return e.get_native_value_();
|
||||||
}
|
}
|
||||||
@ -75,14 +76,15 @@ namespace boost
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename UnderlyingType, typename EnumType>
|
template <typename UnderlyingType, typename EnumType>
|
||||||
UnderlyingType underlying_cast(EnumType v)
|
inline
|
||||||
|
BOOST_CONSTEXPR UnderlyingType underlying_cast(EnumType v) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return static_cast<UnderlyingType>(v);
|
return static_cast<UnderlyingType>(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename EnumType>
|
template <typename EnumType>
|
||||||
inline
|
inline
|
||||||
EnumType native_value(EnumType e)
|
BOOST_CONSTEXPR EnumType native_value(EnumType e) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
@ -96,7 +98,7 @@ namespace boost
|
|||||||
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
|
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
|
||||||
|
|
||||||
#define BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
|
#define BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
|
||||||
explicit operator underlying_type() const BOOST_NOEXCEPT { return get_underlying_value_(); }
|
explicit BOOST_CONSTEXPR operator underlying_type() const BOOST_NOEXCEPT { return get_underlying_value_(); }
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -115,8 +117,8 @@ namespace boost
|
|||||||
typedef void is_boost_scoped_enum_tag; \
|
typedef void is_boost_scoped_enum_tag; \
|
||||||
typedef UnderlyingType underlying_type; \
|
typedef UnderlyingType underlying_type; \
|
||||||
EnumType() BOOST_NOEXCEPT {} \
|
EnumType() BOOST_NOEXCEPT {} \
|
||||||
explicit EnumType(underlying_type v) BOOST_NOEXCEPT : v_(v) {} \
|
explicit BOOST_CONSTEXPR EnumType(underlying_type v) BOOST_NOEXCEPT : v_(v) {} \
|
||||||
underlying_type get_underlying_value_() const BOOST_NOEXCEPT { return v_; } \
|
BOOST_CONSTEXPR underlying_type get_underlying_value_() const BOOST_NOEXCEPT { return v_; } \
|
||||||
BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
|
BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
|
||||||
private: \
|
private: \
|
||||||
underlying_type v_; \
|
underlying_type v_; \
|
||||||
@ -125,30 +127,30 @@ namespace boost
|
|||||||
enum enum_type
|
enum enum_type
|
||||||
|
|
||||||
#define BOOST_SCOPED_ENUM_DECLARE_END2() \
|
#define BOOST_SCOPED_ENUM_DECLARE_END2() \
|
||||||
enum_type get_native_value_() const BOOST_NOEXCEPT { return enum_type(v_); } \
|
BOOST_CONSTEXPR enum_type get_native_value_() const BOOST_NOEXCEPT { return enum_type(v_); } \
|
||||||
friend bool operator ==(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)==enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator ==(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)==enum_type(rhs.v_); } \
|
||||||
friend bool operator ==(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)==rhs; } \
|
friend BOOST_CONSTEXPR bool operator ==(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)==rhs; } \
|
||||||
friend bool operator ==(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs==enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator ==(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs==enum_type(rhs.v_); } \
|
||||||
friend bool operator !=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)!=enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator !=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)!=enum_type(rhs.v_); } \
|
||||||
friend bool operator !=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)!=rhs; } \
|
friend BOOST_CONSTEXPR bool operator !=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)!=rhs; } \
|
||||||
friend bool operator !=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs!=enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator !=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs!=enum_type(rhs.v_); } \
|
||||||
friend bool operator <(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator <(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<enum_type(rhs.v_); } \
|
||||||
friend bool operator <(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<rhs; } \
|
friend BOOST_CONSTEXPR bool operator <(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<rhs; } \
|
||||||
friend bool operator <(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs<enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator <(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs<enum_type(rhs.v_); } \
|
||||||
friend bool operator <=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<=enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator <=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<=enum_type(rhs.v_); } \
|
||||||
friend bool operator <=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<=rhs; } \
|
friend BOOST_CONSTEXPR bool operator <=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<=rhs; } \
|
||||||
friend bool operator <=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs<=enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator <=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs<=enum_type(rhs.v_); } \
|
||||||
friend bool operator >(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator >(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>enum_type(rhs.v_); } \
|
||||||
friend bool operator >(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>rhs; } \
|
friend BOOST_CONSTEXPR bool operator >(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>rhs; } \
|
||||||
friend bool operator >(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs>enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator >(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs>enum_type(rhs.v_); } \
|
||||||
friend bool operator >=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>=enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator >=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>=enum_type(rhs.v_); } \
|
||||||
friend bool operator >=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>=rhs; } \
|
friend BOOST_CONSTEXPR bool operator >=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>=rhs; } \
|
||||||
friend bool operator >=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs>=enum_type(rhs.v_); } \
|
friend BOOST_CONSTEXPR bool operator >=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs>=enum_type(rhs.v_); } \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BOOST_SCOPED_ENUM_DECLARE_END(EnumType) \
|
#define BOOST_SCOPED_ENUM_DECLARE_END(EnumType) \
|
||||||
; \
|
; \
|
||||||
EnumType(enum_type v) BOOST_NOEXCEPT : v_(v) {} \
|
BOOST_CONSTEXPR EnumType(enum_type v) BOOST_NOEXCEPT : v_(v) {} \
|
||||||
BOOST_SCOPED_ENUM_DECLARE_END2()
|
BOOST_SCOPED_ENUM_DECLARE_END2()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user