add comparison operators between ::_enumerated types & Enum types.

This commit is contained in:
Ludwig Fiolka 2025-01-13 11:48:30 +01:00
parent 520d8ee390
commit ad5ed9ba0b

36
enum.h
View File

@ -933,26 +933,62 @@ BETTER_ENUMS_IGNORE_ATTRIBUTES_BEGIN \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \ BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator ==(const Enum &a, const Enum &b) \ inline bool operator ==(const Enum &a, const Enum &b) \
{ return a._to_integral() == b._to_integral(); } \ { return a._to_integral() == b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator ==(const Enum::_enumerated &a, const Enum &b) \
{ return a == b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator ==(const Enum &a, const Enum::_enumerated &b) \
{ return a._to_integral() == b; } \
\ \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \ BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator !=(const Enum &a, const Enum &b) \ inline bool operator !=(const Enum &a, const Enum &b) \
{ return a._to_integral() != b._to_integral(); } \ { return a._to_integral() != b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator !=(const Enum::_enumerated &a, const Enum &b) \
{ return a != b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator !=(const Enum &a, const Enum::_enumerated &b) \
{ return a._to_integral() != b; } \
\ \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \ BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator <(const Enum &a, const Enum &b) \ inline bool operator <(const Enum &a, const Enum &b) \
{ return a._to_integral() < b._to_integral(); } \ { return a._to_integral() < b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator <(const Enum::_enumerated &a, const Enum &b) \
{ return a < b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator <(const Enum &a, const Enum::_enumerated &b) \
{ return a._to_integral() < b; } \
\ \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \ BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator <=(const Enum &a, const Enum &b) \ inline bool operator <=(const Enum &a, const Enum &b) \
{ return a._to_integral() <= b._to_integral(); } \ { return a._to_integral() <= b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator <=(const Enum::_enumerated &a, const Enum &b) \
{ return a <= b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator <=(const Enum &a, const Enum::_enumerated &b) \
{ return a._to_integral() <= b; } \
\ \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \ BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator >(const Enum &a, const Enum &b) \ inline bool operator >(const Enum &a, const Enum &b) \
{ return a._to_integral() > b._to_integral(); } \ { return a._to_integral() > b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator >(const Enum::_enumerated &a, const Enum &b) \
{ return a > b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator >(const Enum &a, const Enum::_enumerated &b) \
{ return a._to_integral() > b; } \
\ \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \ BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator >=(const Enum &a, const Enum &b) \ inline bool operator >=(const Enum &a, const Enum &b) \
{ return a._to_integral() >= b._to_integral(); } \ { return a._to_integral() >= b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator >=(const Enum::_enumerated &a, const Enum &b) \
{ return a >= b._to_integral(); } \
BETTER_ENUMS_UNUSED BETTER_ENUMS_CONSTEXPR_ \
inline bool operator >=(const Enum &a, const Enum::_enumerated &b) \
{ return a._to_integral() >= b; } \
BETTER_ENUMS_IGNORE_ATTRIBUTES_END \ BETTER_ENUMS_IGNORE_ATTRIBUTES_END \
\ \
\ \