[Libreoffice-commits] core.git: include/o3tl o3tl/qa

Stephan Bergmann sbergman at redhat.com
Tue Sep 15 05:32:14 PDT 2015


 include/o3tl/typed_flags_set.hxx |   54 +++++++++++++++++++++++----------------
 o3tl/qa/test-typed_flags.cxx     |    4 ++
 2 files changed, 37 insertions(+), 21 deletions(-)

New commits:
commit fed145be5231c3045098e5a0942f0b9d3c229460
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Sep 15 11:04:14 2015 +0200

    Fix binary ops with two o3tl::type_flags<E>::Wrap params
    
    (the original ones would never have been picked due to how template argument
    deduction works)
    
    Change-Id: I5a08c763d721d8e11b5a10af2344a6a24bb0b9b2
    Reviewed-on: https://gerrit.libreoffice.org/18583
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
    Tested-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/include/o3tl/typed_flags_set.hxx b/include/o3tl/typed_flags_set.hxx
index 0aab70b..b698ae3 100644
--- a/include/o3tl/typed_flags_set.hxx
+++ b/include/o3tl/typed_flags_set.hxx
@@ -68,6 +68,9 @@ struct is_typed_flags {
 
     class Wrap {
     public:
+        typedef typename std::underlying_type<E>::type underlying_type;
+        typedef is_typed_flags Unwrapped;
+
         explicit Wrap(typename std::underlying_type<E>::type value):
             value_(value)
         {
@@ -147,14 +150,17 @@ inline typename o3tl::typed_flags<E>::Wrap operator ^(
         ^ static_cast<typename std::underlying_type<E>::type>(rhs));
 }
 
-template<typename E>
-inline typename o3tl::typed_flags<E>::Wrap operator ^(
-    typename o3tl::typed_flags<E>::Wrap lhs,
-    typename o3tl::typed_flags<E>::Wrap rhs)
+template<typename W>
+inline typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator ^(
+    W lhs, W rhs)
 {
-    return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<typename std::underlying_type<E>::type>(lhs)
-        ^ static_cast<typename std::underlying_type<E>::type>(rhs));
+    return static_cast<W>(
+        static_cast<
+            typename std::underlying_type<typename W::Unwrapped::Self>::type>(
+                lhs)
+        ^ static_cast<
+            typename std::underlying_type<typename W::Unwrapped::Self>::type>(
+                rhs));
 }
 
 template<typename E>
@@ -194,14 +200,17 @@ inline typename o3tl::typed_flags<E>::Wrap operator &(
         & static_cast<typename std::underlying_type<E>::type>(rhs));
 }
 
-template<typename E>
-inline typename o3tl::typed_flags<E>::Wrap operator &(
-    typename o3tl::typed_flags<E>::Wrap lhs,
-    typename o3tl::typed_flags<E>::Wrap rhs)
+template<typename W>
+inline typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator &(
+    W lhs, W rhs)
 {
-    return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<typename std::underlying_type<E>::type>(lhs)
-        & static_cast<typename std::underlying_type<E>::type>(rhs));
+    return static_cast<W>(
+        static_cast<
+            typename std::underlying_type<typename W::Unwrapped::Self>::type>(
+                lhs)
+        & static_cast<
+            typename std::underlying_type<typename W::Unwrapped::Self>::type>(
+                rhs));
 }
 
 template<typename E>
@@ -241,14 +250,17 @@ inline typename o3tl::typed_flags<E>::Wrap operator |(
         | static_cast<typename std::underlying_type<E>::type>(rhs));
 }
 
-template<typename E>
-inline typename o3tl::typed_flags<E>::Wrap operator |(
-    typename o3tl::typed_flags<E>::Wrap lhs,
-    typename o3tl::typed_flags<E>::Wrap rhs)
+template<typename W>
+inline typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator |(
+    W lhs, W rhs)
 {
-    return static_cast<typename o3tl::typed_flags<E>::Wrap>(
-        static_cast<typename std::underlying_type<E>::type>(lhs)
-        | static_cast<typename std::underlying_type<E>::type>(rhs));
+    return static_cast<W>(
+        static_cast<
+            typename std::underlying_type<typename W::Unwrapped::Self>::type>(
+                lhs)
+        | static_cast<
+            typename std::underlying_type<typename W::Unwrapped::Self>::type>(
+                rhs));
 }
 
 template<typename E>
diff --git a/o3tl/qa/test-typed_flags.cxx b/o3tl/qa/test-typed_flags.cxx
index d2a4154..0612fc1 100644
--- a/o3tl/qa/test-typed_flags.cxx
+++ b/o3tl/qa/test-typed_flags.cxx
@@ -47,6 +47,10 @@ public:
         nHint &= ConfigurationChangedHint::ONE;
         CPPUNIT_ASSERT( bool(nHint &= ConfigurationChangedHint::ONE) );
 
+        CPPUNIT_ASSERT(
+            !((ConfigurationChangedHint::NONE | ConfigurationChangedHint::ONE)
+              & (ConfigurationChangedHint::NONE
+                 | ConfigurationChangedHint::TWO)));
     }
 
     // Change the following lines only, if you add, remove or rename


More information about the Libreoffice-commits mailing list