Open yan-zaretskiy opened 4 years ago
I tried to define
bool operator==(MyEnum left, MyEnum::_enumerated right) {
return left._to_integral() == right;
}
This seems to work. Am I thinking along the correct lines?
Every way I know (knew) of avoiding the +
operator had the side effect of introducing ambiguous overload resolution elsewhere. See comments here:
https://github.com/aantron/better-enums/issues/23#issuecomment-231207964 https://github.com/aantron/better-enums/issues/13#issuecomment-160879286
I grant that I may have missed something. Have you run the tests with your modification?
Hmm, trying to build tests complains about the absence of the
Nevermind, install cxxtest...cxxtest/tests.cc
file...
All errors I see are in the 101-special-values.cc
file where you define the invalid_t
and default_t
types, other tests can be built and they pass.
So, just for the reference, cause I don't really know what I'm doing, I added the following lines:
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_ \
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_ \
inline bool operator !=(const Enum::_enumerated &a, const Enum &b) \
{ return a != b._to_integral(); } \
Is it possible to avoid the plus operator for the comparisons between an
Enum
andEnum::_enumerated
?