diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-10-14 14:41:04 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-10-14 14:41:30 +0200 |
commit | 950995222509f059037ff7d73e09d5d9ea2b9b2a (patch) | |
tree | f78770cc3c0f7bed9f10604632fdd20fac744574 /include | |
parent | 9a5e03b8c9d422de43e899e3f880a03dc5c50d84 (diff) |
Reintroduce SFINAE-based selective enablement of &=, |=
...they had erroneously become unconditionally enabled. Also, rename Self to
Wrap.
Change-Id: I574662012bf74114b18f3bab0c1c5825a2bd61bb
Diffstat (limited to 'include')
-rw-r--r-- | include/o3tl/typed_flags_set.hxx | 76 |
1 files changed, 41 insertions, 35 deletions
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<typename E> -inline typename o3tl::typed_flags<E>::Self operator ~(E rhs) { +inline typename o3tl::typed_flags<E>::Wrap operator ~(E rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0); - return static_cast<typename o3tl::typed_flags<E>::Self>( + return static_cast<typename o3tl::typed_flags<E>::Wrap>( o3tl::typed_flags<E>::mask & ~static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs)); } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator ~( - typename o3tl::typed_flags<E>::Self rhs) +inline typename o3tl::typed_flags<E>::Wrap operator ~( + typename o3tl::typed_flags<E>::Wrap rhs) { - return static_cast<typename o3tl::typed_flags<E>::Self>( + return static_cast<typename o3tl::typed_flags<E>::Wrap>( o3tl::typed_flags<E>::mask & ~static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs)); } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator &(E lhs, E rhs) { +inline typename o3tl::typed_flags<E>::Wrap operator &(E lhs, E rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0); - return static_cast<typename o3tl::typed_flags<E>::Self>( + return static_cast<typename o3tl::typed_flags<E>::Wrap>( static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) & static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs)); } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator &( - E lhs, typename o3tl::typed_flags<E>::Self rhs) +inline typename o3tl::typed_flags<E>::Wrap operator &( + E lhs, typename o3tl::typed_flags<E>::Wrap rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); - return static_cast<typename o3tl::typed_flags<E>::Self>( + return static_cast<typename o3tl::typed_flags<E>::Wrap>( static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) & static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs)); } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator &( - typename o3tl::typed_flags<E>::Self lhs, E rhs) +inline typename o3tl::typed_flags<E>::Wrap operator &( + typename o3tl::typed_flags<E>::Wrap lhs, E rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0); - return static_cast<typename o3tl::typed_flags<E>::Self>( + return static_cast<typename o3tl::typed_flags<E>::Wrap>( static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) & static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs)); } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator &( - typename o3tl::typed_flags<E>::Self lhs, - typename o3tl::typed_flags<E>::Self rhs) +inline typename o3tl::typed_flags<E>::Wrap operator &( + typename o3tl::typed_flags<E>::Wrap lhs, + typename o3tl::typed_flags<E>::Wrap rhs) { - return static_cast<typename o3tl::typed_flags<E>::Self>( + return static_cast<typename o3tl::typed_flags<E>::Wrap>( static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) & static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs)); } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator |(E lhs, E rhs) { +inline typename o3tl::typed_flags<E>::Wrap operator |(E lhs, E rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0); - return static_cast<typename o3tl::typed_flags<E>::Self>( + return static_cast<typename o3tl::typed_flags<E>::Wrap>( static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) | static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs)); } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator |( - E lhs, typename o3tl::typed_flags<E>::Self rhs) +inline typename o3tl::typed_flags<E>::Wrap operator |( + E lhs, typename o3tl::typed_flags<E>::Wrap rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); - return static_cast<typename o3tl::typed_flags<E>::Self>( + return static_cast<typename o3tl::typed_flags<E>::Wrap>( static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) | static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs)); } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator |( - typename o3tl::typed_flags<E>::Self lhs, E rhs) +inline typename o3tl::typed_flags<E>::Wrap operator |( + typename o3tl::typed_flags<E>::Wrap lhs, E rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0); - return static_cast<typename o3tl::typed_flags<E>::Self>( + return static_cast<typename o3tl::typed_flags<E>::Wrap>( static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) | static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs)); } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator |( - typename o3tl::typed_flags<E>::Self lhs, - typename o3tl::typed_flags<E>::Self rhs) +inline typename o3tl::typed_flags<E>::Wrap operator |( + typename o3tl::typed_flags<E>::Wrap lhs, + typename o3tl::typed_flags<E>::Wrap rhs) { - return static_cast<typename o3tl::typed_flags<E>::Self>( + return static_cast<typename o3tl::typed_flags<E>::Wrap>( static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) | static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs)); } template<typename E> -inline E operator &=(E & lhs, E rhs) { +inline typename o3tl::typed_flags<E>::Self operator &=(E & lhs, E rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0); lhs = lhs & rhs; @@ -185,14 +187,16 @@ inline E operator &=(E & lhs, E rhs) { } template<typename E> -inline E operator &=(E & lhs, typename o3tl::typed_flags<E>::Self rhs) { +inline typename o3tl::typed_flags<E>::Self operator &=( + E & lhs, typename o3tl::typed_flags<E>::Wrap rhs) +{ assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); lhs = lhs & rhs; return lhs; } template<typename E> -inline E operator |=(E & lhs, E rhs) { +inline typename o3tl::typed_flags<E>::Self operator |=(E & lhs, E rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0); lhs = lhs | rhs; @@ -200,7 +204,9 @@ inline E operator |=(E & lhs, E rhs) { } template<typename E> -inline E operator |=(E & lhs, typename o3tl::typed_flags<E>::Self rhs) { +inline typename o3tl::typed_flags<E>::Self operator |=( + E & lhs, typename o3tl::typed_flags<E>::Wrap rhs) +{ assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); lhs = lhs | rhs; return lhs; |