Change flags operator& to return a value convertible both to flags and bool

This commit is contained in:
Maxime Coste 2015-03-16 18:57:18 +00:00
parent eb41d25006
commit 4770d3d86c

View File

@ -28,10 +28,18 @@ Flags& operator|=(Flags& lhs, Flags rhs)
return lhs;
}
template<typename Flags, typename = EnableIfWithBitOps<Flags>>
constexpr bool operator&(Flags lhs, Flags rhs)
template<typename Flags>
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>>