summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-03-16 18:57:18 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-03-16 18:57:18 +0000
commit4770d3d86cf5f69b22d96d6435c840f001a38368 (patch)
treea6a4a11ddff90d94da1bd1161d007164a754e968 /src
parenteb41d250061c1c1385ff334898009910b97a93f4 (diff)
Change flags operator& to return a value convertible both to flags and bool
Diffstat (limited to 'src')
-rw-r--r--src/flags.hh12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/flags.hh b/src/flags.hh
index 10e05187..2b68751b 100644
--- a/src/flags.hh
+++ b/src/flags.hh
@@ -28,10 +28,18 @@ Flags& operator|=(Flags& lhs, Flags rhs)
return lhs;
}
+template<typename Flags>
+struct TestableFlags
+{
+ Flags value;
+ constexpr operator bool() const { return (UnderlyingType<Flags>)value; }
+ constexpr operator Flags() const { return value; }
+};
+
template<typename Flags, typename = EnableIfWithBitOps<Flags>>
-constexpr bool operator&(Flags lhs, Flags rhs)
+constexpr TestableFlags<Flags> operator&(Flags lhs, Flags rhs)
{
- return ((UnderlyingType<Flags>) lhs & (UnderlyingType<Flags>) rhs) == (UnderlyingType<Flags>)rhs;
+ return { (Flags)((UnderlyingType<Flags>) lhs & (UnderlyingType<Flags>) rhs) };
}
template<typename Flags, typename = EnableIfWithBitOps<Flags>>