subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1849553 - in /subversion/trunk/subversion/bindings/cxx: include/svnxx/tristate.hpp tests/test_tristate.cpp
Date Sat, 22 Dec 2018 14:14:13 GMT
Author: brane
Date: Sat Dec 22 14:14:12 2018
New Revision: 1849553

URL: http://svn.apache.org/viewvc?rev=1849553&view=rev
Log:
In SVN++, move the 'unknown' predicate out of the 'tristate' class.

* subversion/bindings/cxx/include/svnxx/tristate.hpp
  (tristate::unknown(tristate)): Removed.
  (unknown(tristate)): Moved here, doesn't use private knowledge about
   the tristate class.
  (operator||, operator==): Use the new namespace-scope 'unknown' predicate.

* subversion/bindings/cxx/tests/test_tristate.cpp: Update all test cases to
   use the 'svn::unknown(tristate)' predicate.

Modified:
    subversion/trunk/subversion/bindings/cxx/include/svnxx/tristate.hpp
    subversion/trunk/subversion/bindings/cxx/tests/test_tristate.cpp

Modified: subversion/trunk/subversion/bindings/cxx/include/svnxx/tristate.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/include/svnxx/tristate.hpp?rev=1849553&r1=1849552&r2=1849553&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/include/svnxx/tristate.hpp (original)
+++ subversion/trunk/subversion/bindings/cxx/include/svnxx/tristate.hpp Sat Dec 22 14:14:12
2018
@@ -79,7 +79,9 @@ public:
    * @brief Factory method for the @e unknown state.
    */
   static constexpr tristate unknown() noexcept
-    { return tristate(/*unknown_value*/); }
+    {
+      return tristate(/*unknown_value*/);
+    }
 
   /**
    * @brief Constructor for the @e true and @e false states.
@@ -94,7 +96,9 @@ public:
    * @e true state.
    */
   constexpr operator safe_bool() const noexcept
-    { return value == true_value ? &impl::trueval : 0; }
+    {
+      return value == true_value ? &impl::trueval : 0;
+    }
 
   /**
    * @brief Logical negation.
@@ -126,13 +130,6 @@ public:
                  : tristate::unknown()));
     }
 
-  /**
-   * @brief Test for the @e unknown state.
-   * @returns @c true only if @a t is the @e unknown state.
-   */
-  static constexpr bool unknown(tristate t) noexcept
-    { return t.value == unknown_value; }
-
 private:
   // See svn_tristate_t in svn_types.h.
   enum: unsigned char {
@@ -144,6 +141,16 @@ private:
 
 /**
  * @related tristate
+ * @brief Test for the @e unknown @c tristate state.
+ * @returns @c true only if @a t is the @e * unknown state.
+ */
+constexpr inline bool unknown(tristate t) noexcept
+{
+  return bool(t) == bool(!t);
+}
+
+/**
+ * @related tristate
  * @brief Logical conjunction.
  * @returns the result of a logical @c AND of two @c tristate
  * values, according to the following table:
@@ -290,8 +297,7 @@ constexpr inline tristate operator||(boo
  */
 constexpr inline tristate operator==(tristate t, tristate u) noexcept
 {
-  return (tristate::unknown(t) || tristate::unknown(u)
-          ? tristate::unknown()
+  return (unknown(t) || unknown(u) ? tristate::unknown()
           : ((t && u) || (!t && !u)));
 }
 
@@ -347,8 +353,7 @@ constexpr inline tristate operator==(boo
  */
 constexpr inline tristate operator!=(tristate t, tristate u) noexcept
 {
-  return (tristate::unknown(t) || tristate::unknown(u)
-          ? tristate::unknown()
+  return (unknown(t) || unknown(u) ? tristate::unknown()
           : !((t && u) || (!t && !u)));
 }
 

Modified: subversion/trunk/subversion/bindings/cxx/tests/test_tristate.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/tests/test_tristate.cpp?rev=1849553&r1=1849552&r2=1849553&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/tests/test_tristate.cpp (original)
+++ subversion/trunk/subversion/bindings/cxx/tests/test_tristate.cpp Sat Dec 22 14:14:12 2018
@@ -36,9 +36,9 @@ constexpr auto X = svn::tristate::unknow
 
 BOOST_AUTO_TEST_CASE(constants)
 {
-  BOOST_TEST(!svn::tristate::unknown(T));
-  BOOST_TEST(!svn::tristate::unknown(F));
-  BOOST_TEST(svn::tristate::unknown(X));
+  BOOST_TEST(!svn::unknown(T));
+  BOOST_TEST(!svn::unknown(F));
+  BOOST_TEST(svn::unknown(X));
 
   BOOST_TEST(bool(T));
   BOOST_TEST(!bool(!T));
@@ -58,13 +58,13 @@ BOOST_AUTO_TEST_CASE(conversions)
 
   BOOST_TEST(detail::convert(svn_tristate_true) == T);
   BOOST_TEST(detail::convert(svn_tristate_false) == F);
-  BOOST_TEST(svn::tristate::unknown(detail::convert(svn_tristate_unknown)));
+  BOOST_TEST(svn::unknown(detail::convert(svn_tristate_unknown)));
 }
 
 BOOST_AUTO_TEST_CASE(construct_true)
 {
   constexpr auto state = svn::tristate(true);
-  BOOST_TEST(!svn::tristate::unknown(state));
+  BOOST_TEST(!svn::unknown(state));
   BOOST_TEST(bool(state));
   BOOST_TEST(!bool(!state));
 }
@@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(construct_true)
 BOOST_AUTO_TEST_CASE(construct_false)
 {
   constexpr auto state = svn::tristate(false);
-  BOOST_TEST(!svn::tristate::unknown(state));
+  BOOST_TEST(!svn::unknown(state));
   BOOST_TEST(!bool(state));
   BOOST_TEST(bool(!state));
 }
@@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(construct_false)
 BOOST_AUTO_TEST_CASE(construct_unknown)
 {
   constexpr auto state = svn::tristate::unknown();
-  BOOST_TEST(svn::tristate::unknown(state));
+  BOOST_TEST(svn::unknown(state));
   BOOST_TEST(!bool(state));
   BOOST_TEST(!bool(!state));
 }
@@ -91,11 +91,11 @@ BOOST_AUTO_TEST_CASE(tristate_and_trista
   BOOST_TEST((T && F) == F);
   BOOST_TEST((F && T) == F);
   BOOST_TEST((F && F) == F);
-  BOOST_TEST(svn::tristate::unknown(T && X));
-  BOOST_TEST(svn::tristate::unknown(X && T));
+  BOOST_TEST(svn::unknown(T && X));
+  BOOST_TEST(svn::unknown(X && T));
   BOOST_TEST((F && X) == F);
   BOOST_TEST((X && F) == F);
-  BOOST_TEST(svn::tristate::unknown(X && X));
+  BOOST_TEST(svn::unknown(X && X));
 }
 
 BOOST_AUTO_TEST_CASE(tristate_and_bool)
@@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(tristate_and_bool)
   BOOST_TEST((T && false) == F);
   BOOST_TEST((F &&  true) == F);
   BOOST_TEST((F && false) == F);
-  BOOST_TEST(svn::tristate::unknown(X && true));
+  BOOST_TEST(svn::unknown(X && true));
   BOOST_TEST((X && false) == F);
 }
 
@@ -114,7 +114,7 @@ BOOST_AUTO_TEST_CASE(bool_and_tristate)
   BOOST_TEST((false && T) == F);
   BOOST_TEST((true  && F) == F);
   BOOST_TEST((false && F) == F);
-  BOOST_TEST(svn::tristate::unknown(true && X));
+  BOOST_TEST(svn::unknown(true && X));
   BOOST_TEST((false && X) == F);
 }
 
@@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(tristate_and_number
   BOOST_TEST((T &&  0) == F);
   BOOST_TEST((F && -1) == F);
   BOOST_TEST((F &&  0) == F);
-  BOOST_TEST(svn::tristate::unknown(X &&  5));
+  BOOST_TEST(svn::unknown(X &&  5));
   BOOST_TEST((X &&  0) == F);
 }
 
@@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE(number_and_tristate
   BOOST_TEST(( 0 && T) == F);
   BOOST_TEST((~0 && F) == F);
   BOOST_TEST(( 0 && F) == F);
-  BOOST_TEST(svn::tristate::unknown(07 && X));
+  BOOST_TEST(svn::unknown(07 && X));
   BOOST_TEST(( 0 && X) == F);
 }
 
@@ -147,9 +147,9 @@ BOOST_AUTO_TEST_CASE(tristate_or_tristat
   BOOST_TEST((F || F) == F);
   BOOST_TEST((T || X) == T);
   BOOST_TEST((X || T) == T);
-  BOOST_TEST(svn::tristate::unknown(F || X));
-  BOOST_TEST(svn::tristate::unknown(X || F));
-  BOOST_TEST(svn::tristate::unknown(X || X));
+  BOOST_TEST(svn::unknown(F || X));
+  BOOST_TEST(svn::unknown(X || F));
+  BOOST_TEST(svn::unknown(X || X));
 }
 
 BOOST_AUTO_TEST_CASE(tristate_or_bool)
@@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE(tristate_or_bool)
   BOOST_TEST((F ||  true) == T);
   BOOST_TEST((F || false) == F);
   BOOST_TEST((X ||  true) == T);
-  BOOST_TEST(svn::tristate::unknown(X || false));
+  BOOST_TEST(svn::unknown(X || false));
 }
 
 BOOST_AUTO_TEST_CASE(bool_or_tristate)
@@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(bool_or_tristate)
   BOOST_TEST((true  || F) == T);
   BOOST_TEST((false || F) == F);
   BOOST_TEST((true  || X) == T);
-  BOOST_TEST(svn::tristate::unknown(false || X));
+  BOOST_TEST(svn::unknown(false || X));
 }
 
 BOOST_AUTO_TEST_CASE(tristate_or_number)
@@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(tristate_or_number)
   BOOST_TEST((F || -1) == T);
   BOOST_TEST((F ||  0) == F);
   BOOST_TEST((X ||  5) == T);
-  BOOST_TEST(svn::tristate::unknown(X || 0));
+  BOOST_TEST(svn::unknown(X || 0));
 }
 
 BOOST_AUTO_TEST_CASE(number_or_tristate)
@@ -190,20 +190,20 @@ BOOST_AUTO_TEST_CASE(number_or_tristate)
   BOOST_TEST((~0 || F) == T);
   BOOST_TEST(( 0 || F) == F);
   BOOST_TEST((07 || X) == T);
-  BOOST_TEST(svn::tristate::unknown(0 || X));
+  BOOST_TEST(svn::unknown(0 || X));
 }
 
 BOOST_AUTO_TEST_CASE(tristate_eq_tristate)
 {
   BOOST_TEST((T == T) == T);
   BOOST_TEST((T == F) == F);
-  BOOST_TEST(svn::tristate::unknown(T == X));
+  BOOST_TEST(svn::unknown(T == X));
   BOOST_TEST((F == T) == F);
   BOOST_TEST((F == F) == T);
-  BOOST_TEST(svn::tristate::unknown(F == X));
-  BOOST_TEST(svn::tristate::unknown(X == T));
-  BOOST_TEST(svn::tristate::unknown(X == F));
-  BOOST_TEST(svn::tristate::unknown(X == X));
+  BOOST_TEST(svn::unknown(F == X));
+  BOOST_TEST(svn::unknown(X == T));
+  BOOST_TEST(svn::unknown(X == F));
+  BOOST_TEST(svn::unknown(X == X));
 }
 
 BOOST_AUTO_TEST_CASE(tristate_eq_bool)
@@ -212,8 +212,8 @@ BOOST_AUTO_TEST_CASE(tristate_eq_bool)
   BOOST_TEST((T == false) == F);
   BOOST_TEST((F ==  true) == F);
   BOOST_TEST((F == false) == T);
-  BOOST_TEST(svn::tristate::unknown(X == true));
-  BOOST_TEST(svn::tristate::unknown(X == false));
+  BOOST_TEST(svn::unknown(X == true));
+  BOOST_TEST(svn::unknown(X == false));
 }
 
 BOOST_AUTO_TEST_CASE(bool_eq_tristate)
@@ -222,21 +222,21 @@ BOOST_AUTO_TEST_CASE(bool_eq_tristate)
   BOOST_TEST((false == T) == F);
   BOOST_TEST((true  == F) == F);
   BOOST_TEST((false == F) == T);
-  BOOST_TEST(svn::tristate::unknown(true  == X));
-  BOOST_TEST(svn::tristate::unknown(false == X));
+  BOOST_TEST(svn::unknown(true  == X));
+  BOOST_TEST(svn::unknown(false == X));
 }
 
 BOOST_AUTO_TEST_CASE(tristate_neq_tristate)
 {
   BOOST_TEST((T != T) == F);
   BOOST_TEST((T != F) == T);
-  BOOST_TEST(svn::tristate::unknown(T != X));
+  BOOST_TEST(svn::unknown(T != X));
   BOOST_TEST((F != T) == T);
   BOOST_TEST((F != F) == F);
-  BOOST_TEST(svn::tristate::unknown(F != X));
-  BOOST_TEST(svn::tristate::unknown(X != T));
-  BOOST_TEST(svn::tristate::unknown(X != F));
-  BOOST_TEST(svn::tristate::unknown(X != X));
+  BOOST_TEST(svn::unknown(F != X));
+  BOOST_TEST(svn::unknown(X != T));
+  BOOST_TEST(svn::unknown(X != F));
+  BOOST_TEST(svn::unknown(X != X));
 }
 
 BOOST_AUTO_TEST_CASE(tristate_neq_bool)
@@ -245,8 +245,8 @@ BOOST_AUTO_TEST_CASE(tristate_neq_bool)
   BOOST_TEST((T != false) == T);
   BOOST_TEST((F !=  true) == T);
   BOOST_TEST((F != false) == F);
-  BOOST_TEST(svn::tristate::unknown(X != true));
-  BOOST_TEST(svn::tristate::unknown(X != false));
+  BOOST_TEST(svn::unknown(X != true));
+  BOOST_TEST(svn::unknown(X != false));
 }
 
 BOOST_AUTO_TEST_CASE(bool_neq_tristate)
@@ -255,8 +255,8 @@ BOOST_AUTO_TEST_CASE(bool_neq_tristate)
   BOOST_TEST((false != T) == T);
   BOOST_TEST((true  != F) == T);
   BOOST_TEST((false != F) == F);
-  BOOST_TEST(svn::tristate::unknown(true  != X));
-  BOOST_TEST(svn::tristate::unknown(false != X));
+  BOOST_TEST(svn::unknown(true  != X));
+  BOOST_TEST(svn::unknown(false != X));
 }
 
 BOOST_AUTO_TEST_SUITE_END();



Mime
View raw message