From 950995222509f059037ff7d73e09d5d9ea2b9b2a Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 14 Oct 2014 14:41:04 +0200 Subject: Reintroduce SFINAE-based selective enablement of &=, |= ...they had erroneously become unconditionally enabled. Also, rename Self to Wrap. Change-Id: I574662012bf74114b18f3bab0c1c5825a2bd61bb --- include/o3tl/typed_flags_set.hxx | 76 ++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 35 deletions(-) (limited to 'include/o3tl') diff --git a/include/o3tl/typed_flags_set.hxx b/include/o3tl/typed_flags_set.hxx index 1aac62512273..016f8eb805a8 100644 --- a/include/o3tl/typed_flags_set.hxx +++ b/include/o3tl/typed_flags_set.hxx @@ -54,9 +54,11 @@ struct is_typed_flags { static_assert( M >= 0, "is_typed_flags expects only non-negative bit values"); - class Self { + typedef E Self; + + class Wrap { public: - explicit Self(O3TL_STD_UNDERLYING_TYPE_E value): + explicit Wrap(O3TL_STD_UNDERLYING_TYPE_E value): value_(value) { assert(value >= 0); } @@ -82,102 +84,102 @@ struct is_typed_flags { } template -inline typename o3tl::typed_flags::Self operator ~(E rhs) { +inline typename o3tl::typed_flags::Wrap operator ~(E rhs) { assert(static_cast(rhs) >= 0); - return static_cast::Self>( + return static_cast::Wrap>( o3tl::typed_flags::mask & ~static_cast(rhs)); } template -inline typename o3tl::typed_flags::Self operator ~( - typename o3tl::typed_flags::Self rhs) +inline typename o3tl::typed_flags::Wrap operator ~( + typename o3tl::typed_flags::Wrap rhs) { - return static_cast::Self>( + return static_cast::Wrap>( o3tl::typed_flags::mask & ~static_cast(rhs)); } template -inline typename o3tl::typed_flags::Self operator &(E lhs, E rhs) { +inline typename o3tl::typed_flags::Wrap operator &(E lhs, E rhs) { assert(static_cast(lhs) >= 0); assert(static_cast(rhs) >= 0); - return static_cast::Self>( + return static_cast::Wrap>( static_cast(lhs) & static_cast(rhs)); } template -inline typename o3tl::typed_flags::Self operator &( - E lhs, typename o3tl::typed_flags::Self rhs) +inline typename o3tl::typed_flags::Wrap operator &( + E lhs, typename o3tl::typed_flags::Wrap rhs) { assert(static_cast(lhs) >= 0); - return static_cast::Self>( + return static_cast::Wrap>( static_cast(lhs) & static_cast(rhs)); } template -inline typename o3tl::typed_flags::Self operator &( - typename o3tl::typed_flags::Self lhs, E rhs) +inline typename o3tl::typed_flags::Wrap operator &( + typename o3tl::typed_flags::Wrap lhs, E rhs) { assert(static_cast(rhs) >= 0); - return static_cast::Self>( + return static_cast::Wrap>( static_cast(lhs) & static_cast(rhs)); } template -inline typename o3tl::typed_flags::Self operator &( - typename o3tl::typed_flags::Self lhs, - typename o3tl::typed_flags::Self rhs) +inline typename o3tl::typed_flags::Wrap operator &( + typename o3tl::typed_flags::Wrap lhs, + typename o3tl::typed_flags::Wrap rhs) { - return static_cast::Self>( + return static_cast::Wrap>( static_cast(lhs) & static_cast(rhs)); } template -inline typename o3tl::typed_flags::Self operator |(E lhs, E rhs) { +inline typename o3tl::typed_flags::Wrap operator |(E lhs, E rhs) { assert(static_cast(lhs) >= 0); assert(static_cast(rhs) >= 0); - return static_cast::Self>( + return static_cast::Wrap>( static_cast(lhs) | static_cast(rhs)); } template -inline typename o3tl::typed_flags::Self operator |( - E lhs, typename o3tl::typed_flags::Self rhs) +inline typename o3tl::typed_flags::Wrap operator |( + E lhs, typename o3tl::typed_flags::Wrap rhs) { assert(static_cast(lhs) >= 0); - return static_cast::Self>( + return static_cast::Wrap>( static_cast(lhs) | static_cast(rhs)); } template -inline typename o3tl::typed_flags::Self operator |( - typename o3tl::typed_flags::Self lhs, E rhs) +inline typename o3tl::typed_flags::Wrap operator |( + typename o3tl::typed_flags::Wrap lhs, E rhs) { assert(static_cast(rhs) >= 0); - return static_cast::Self>( + return static_cast::Wrap>( static_cast(lhs) | static_cast(rhs)); } template -inline typename o3tl::typed_flags::Self operator |( - typename o3tl::typed_flags::Self lhs, - typename o3tl::typed_flags::Self rhs) +inline typename o3tl::typed_flags::Wrap operator |( + typename o3tl::typed_flags::Wrap lhs, + typename o3tl::typed_flags::Wrap rhs) { - return static_cast::Self>( + return static_cast::Wrap>( static_cast(lhs) | static_cast(rhs)); } template -inline E operator &=(E & lhs, E rhs) { +inline typename o3tl::typed_flags::Self operator &=(E & lhs, E rhs) { assert(static_cast(lhs) >= 0); assert(static_cast(rhs) >= 0); lhs = lhs & rhs; @@ -185,14 +187,16 @@ inline E operator &=(E & lhs, E rhs) { } template -inline E operator &=(E & lhs, typename o3tl::typed_flags::Self rhs) { +inline typename o3tl::typed_flags::Self operator &=( + E & lhs, typename o3tl::typed_flags::Wrap rhs) +{ assert(static_cast(lhs) >= 0); lhs = lhs & rhs; return lhs; } template -inline E operator |=(E & lhs, E rhs) { +inline typename o3tl::typed_flags::Self operator |=(E & lhs, E rhs) { assert(static_cast(lhs) >= 0); assert(static_cast(rhs) >= 0); lhs = lhs | rhs; @@ -200,7 +204,9 @@ inline E operator |=(E & lhs, E rhs) { } template -inline E operator |=(E & lhs, typename o3tl::typed_flags::Self rhs) { +inline typename o3tl::typed_flags::Self operator |=( + E & lhs, typename o3tl::typed_flags::Wrap rhs) +{ assert(static_cast(lhs) >= 0); lhs = lhs | rhs; return lhs; -- cgit