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; 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>>