mirror of
https://github.com/aantron/better-enums.git
synced 2025-12-08 01:36:44 +08:00
Reordered some member functions.
Microsoft's incomplete constexpr implementation does not currently allow constexpr use of constexpr functions that are defined out of line below their point of use. The reordering in this commit is a workaround. While this still doesn't give MSVC constexpr support due to additional bugs in Microsoft's implementation, maintaining the member functions in this order makes it easier to begin each attempt to work around the remaining compiler bugs.
This commit is contained in:
parent
8061c24191
commit
e9b6792922
104
enum.h
104
enum.h
@ -684,6 +684,39 @@ operator +(Enum::_enumerated enumerated) \
|
||||
return (Enum)enumerated; \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional_index \
|
||||
Enum::_from_value_loop(Enum::_integral value, std::size_t index) \
|
||||
{ \
|
||||
return \
|
||||
index == _size() ? \
|
||||
_optional_index() : \
|
||||
BETTER_ENUMS__NS(Enum)::_value_array[index]._value == value ? \
|
||||
_optional_index(index) : \
|
||||
_from_value_loop(value, index + 1); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional_index \
|
||||
Enum::_from_string_loop(const char *name, std::size_t index) \
|
||||
{ \
|
||||
return \
|
||||
index == _size() ? _optional_index() : \
|
||||
::better_enums::_names_match( \
|
||||
BETTER_ENUMS__NS(Enum)::_raw_names()[index], name) ? \
|
||||
_optional_index(index) : \
|
||||
_from_string_loop(name, index + 1); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional_index \
|
||||
Enum::_from_string_nocase_loop(const char *name, std::size_t index) \
|
||||
{ \
|
||||
return \
|
||||
index == _size() ? _optional_index() : \
|
||||
::better_enums::_names_match_nocase( \
|
||||
BETTER_ENUMS__NS(Enum)::_raw_names()[index], name) ? \
|
||||
_optional_index(index) : \
|
||||
_from_string_nocase_loop(name, index + 1); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_integral Enum::_to_integral() const \
|
||||
{ \
|
||||
return _integral(_value); \
|
||||
@ -695,6 +728,14 @@ Enum::_from_integral_unchecked(_integral value) \
|
||||
return (_enumerated)value; \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional \
|
||||
Enum::_from_integral_nothrow(_integral value) \
|
||||
{ \
|
||||
return \
|
||||
::better_enums::_map_index<Enum>(BETTER_ENUMS__NS(Enum)::_value_array, \
|
||||
_from_value_loop(value)); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__IF_EXCEPTIONS( \
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum Enum::_from_integral(_integral value) \
|
||||
{ \
|
||||
@ -704,14 +745,6 @@ BETTER_ENUMS__CONSTEXPR inline Enum Enum::_from_integral(_integral value) \
|
||||
} \
|
||||
) \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional \
|
||||
Enum::_from_integral_nothrow(_integral value) \
|
||||
{ \
|
||||
return \
|
||||
::better_enums::_map_index<Enum>(BETTER_ENUMS__NS(Enum)::_value_array, \
|
||||
_from_value_loop(value)); \
|
||||
} \
|
||||
\
|
||||
ToStringConstexpr inline const char* Enum::_to_string() const \
|
||||
{ \
|
||||
return \
|
||||
@ -721,6 +754,14 @@ ToStringConstexpr inline const char* Enum::_to_string() const \
|
||||
_from_value_loop(CallInitialize(_value)))); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional \
|
||||
Enum::_from_string_nothrow(const char *name) \
|
||||
{ \
|
||||
return \
|
||||
::better_enums::_map_index<Enum>( \
|
||||
BETTER_ENUMS__NS(Enum)::_value_array, _from_string_loop(name)); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__IF_EXCEPTIONS( \
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum Enum::_from_string(const char *name) \
|
||||
{ \
|
||||
@ -731,11 +772,11 @@ BETTER_ENUMS__CONSTEXPR inline Enum Enum::_from_string(const char *name) \
|
||||
) \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional \
|
||||
Enum::_from_string_nothrow(const char *name) \
|
||||
Enum::_from_string_nocase_nothrow(const char *name) \
|
||||
{ \
|
||||
return \
|
||||
::better_enums::_map_index<Enum>( \
|
||||
BETTER_ENUMS__NS(Enum)::_value_array, _from_string_loop(name)); \
|
||||
::better_enums::_map_index<Enum>(BETTER_ENUMS__NS(Enum)::_value_array, \
|
||||
_from_string_nocase_loop(name)); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__IF_EXCEPTIONS( \
|
||||
@ -748,14 +789,6 @@ BETTER_ENUMS__CONSTEXPR inline Enum Enum::_from_string_nocase(const char *name)\
|
||||
} \
|
||||
) \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional \
|
||||
Enum::_from_string_nocase_nothrow(const char *name) \
|
||||
{ \
|
||||
return \
|
||||
::better_enums::_map_index<Enum>(BETTER_ENUMS__NS(Enum)::_value_array, \
|
||||
_from_string_nocase_loop(name)); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline bool Enum::_is_valid(_integral value) \
|
||||
{ \
|
||||
return _from_value_loop(value); \
|
||||
@ -790,39 +823,6 @@ ToStringConstexpr inline Enum::_name_iterable Enum::_names() \
|
||||
\
|
||||
DefineInitialize(Enum) \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional_index \
|
||||
Enum::_from_value_loop(Enum::_integral value, std::size_t index) \
|
||||
{ \
|
||||
return \
|
||||
index == _size() ? \
|
||||
_optional_index() : \
|
||||
BETTER_ENUMS__NS(Enum)::_value_array[index]._value == value ? \
|
||||
_optional_index(index) : \
|
||||
_from_value_loop(value, index + 1); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional_index \
|
||||
Enum::_from_string_loop(const char *name, std::size_t index) \
|
||||
{ \
|
||||
return \
|
||||
index == _size() ? _optional_index() : \
|
||||
::better_enums::_names_match( \
|
||||
BETTER_ENUMS__NS(Enum)::_raw_names()[index], name) ? \
|
||||
_optional_index(index) : \
|
||||
_from_string_loop(name, index + 1); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline Enum::_optional_index \
|
||||
Enum::_from_string_nocase_loop(const char *name, std::size_t index) \
|
||||
{ \
|
||||
return \
|
||||
index == _size() ? _optional_index() : \
|
||||
::better_enums::_names_match_nocase( \
|
||||
BETTER_ENUMS__NS(Enum)::_raw_names()[index], name) ? \
|
||||
_optional_index(index) : \
|
||||
_from_string_nocase_loop(name, index + 1); \
|
||||
} \
|
||||
\
|
||||
BETTER_ENUMS__CONSTEXPR inline bool operator ==(const Enum &a, const Enum &b) \
|
||||
{ return a._to_integral() == b._to_integral(); } \
|
||||
BETTER_ENUMS__CONSTEXPR inline bool operator !=(const Enum &a, const Enum &b) \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user