Change flags operator& to return a value convertible both to flags and bool
This commit is contained in:
parent
eb41d25006
commit
4770d3d86c
14
src/flags.hh
14
src/flags.hh
|
@ -28,10 +28,18 @@ Flags& operator|=(Flags& lhs, Flags rhs)
|
||||||
return lhs;
|
return lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Flags, typename = EnableIfWithBitOps<Flags>>
|
template<typename Flags>
|
||||||
constexpr bool operator&(Flags lhs, Flags rhs)
|
struct TestableFlags
|
||||||
{
|
{
|
||||||
return ((UnderlyingType<Flags>) lhs & (UnderlyingType<Flags>) rhs) == (UnderlyingType<Flags>)rhs;
|
Flags value;
|
||||||
|
constexpr operator bool() const { return (UnderlyingType<Flags>)value; }
|
||||||
|
constexpr operator Flags() const { return value; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Flags, typename = EnableIfWithBitOps<Flags>>
|
||||||
|
constexpr TestableFlags<Flags> operator&(Flags lhs, Flags rhs)
|
||||||
|
{
|
||||||
|
return { (Flags)((UnderlyingType<Flags>) lhs & (UnderlyingType<Flags>) rhs) };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Flags, typename = EnableIfWithBitOps<Flags>>
|
template<typename Flags, typename = EnableIfWithBitOps<Flags>>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user