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