From 4770d3d86cf5f69b22d96d6435c840f001a38368 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 16 Mar 2015 18:57:18 +0000 Subject: Change flags operator& to return a value convertible both to flags and bool --- src/flags.hh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/flags.hh') 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 +struct TestableFlags +{ + Flags value; + constexpr operator bool() const { return (UnderlyingType)value; } + constexpr operator Flags() const { return value; } +}; + template> -constexpr bool operator&(Flags lhs, Flags rhs) +constexpr TestableFlags operator&(Flags lhs, Flags rhs) { - return ((UnderlyingType) lhs & (UnderlyingType) rhs) == (UnderlyingType)rhs; + return { (Flags)((UnderlyingType) lhs & (UnderlyingType) rhs) }; } template> -- cgit v1.2.3