Fix enum vs integer comparison in se_t::operator==

Need to convert left part to its underlying type.
This commit is contained in:
Nekotekina 2019-09-29 16:01:47 +03:00
parent 0f567abdd8
commit 5f29840348

View File

@ -199,10 +199,21 @@ namespace stx
{
using R = simple_t<T2>;
if constexpr ((std::is_integral_v<T> || std::is_enum_v<T>) && (std::is_integral_v<R> || std::is_enum_v<R>) && sizeof(T) >= sizeof(R))
if constexpr ((std::is_integral_v<T> || std::is_enum_v<T>) && (std::is_integral_v<R> || std::is_enum_v<R>))
{
if constexpr (sizeof(T) >= sizeof(R))
{
if constexpr (std::is_enum_v<T> && std::is_convertible_v<T, int> && std::is_convertible_v<R, int>)
{
using under = std::underlying_type_t<T>;
return std::bit_cast<under>(m_data) == std::bit_cast<under>(static_cast<se_t<under, Swap>>(rhs));
}
else
{
return std::bit_cast<type>(m_data) == std::bit_cast<type>(static_cast<se_t>(rhs));
}
}
}
// Keep outside of if constexpr to make sure it fails on invalid comparison
return value() == rhs;