lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 2598df5 6/8: Dispense with boost/operators fo


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 2598df5 6/8: Dispense with boost/operators for one class
Date: Sun, 25 Feb 2018 17:15:14 -0500 (EST)

branch: master
commit 2598df5fbc5adc0c879598e149e3ce7097bfe4b2
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Dispense with boost/operators for one class
    
    Revised the unit test to restrict equality comparisons to the underlying
    arithmetic type. With boost/operators, the original tests passed, even
    when comparing tn_range<unsigned int, percentage_trammel<unsigned int>>
    to signed int (with potentially problematic consequences); now, that
    tn_range type is comparable only to unsigned int, so the unit tests had
    to be revised to test that comparison only.
---
 tn_range.hpp      | 40 +++++++++++++++++++++++++++++++++++-----
 tn_range.tpp      | 18 ++++++++++++++++++
 tn_range_test.cpp | 22 +++++++++++-----------
 3 files changed, 64 insertions(+), 16 deletions(-)

diff --git a/tn_range.hpp b/tn_range.hpp
index dd07b06..b76ee01 100644
--- a/tn_range.hpp
+++ b/tn_range.hpp
@@ -26,8 +26,6 @@
 
 #include "datum_base.hpp"
 
-#include <boost/operators.hpp>
-
 #include <string>
 #include <type_traits>
 #include <typeinfo>
@@ -230,9 +228,6 @@ class LMI_SO tn_range_base
 template<typename Number, typename Trammel>
 class tn_range
     :public tn_range_base
-    ,private boost::totally_ordered    <tn_range<Number,Trammel>>
-    ,private boost::equality_comparable<tn_range<Number,Trammel>,Number>
-    ,private boost::equality_comparable<tn_range<Number,Trammel>,std::string>
 {
     static_assert(std::is_base_of<trammel_base<Number>,Trammel>::value);
 
@@ -260,6 +255,9 @@ class tn_range
     bool operator==(tn_range<Number,Trammel> const&) const;
     bool operator==(Number) const;
     bool operator==(std::string const&) const;
+    bool operator!=(tn_range<Number,Trammel> const&) const;
+    bool operator!=(Number) const;
+    bool operator!=(std::string const&) const;
     bool operator<(tn_range<Number,Trammel> const&) const;
 
     Trammel const& trammel() const;
@@ -290,5 +288,37 @@ class tn_range
     Number value_;
 };
 
+// Define these few equality operators inline.
+//
+// To avoid bloat, great pains are taken to instantiate tn_range types
+// explicitly in a single translation unit. The same could be done for
+// these operators; however, explicit instantiations of four operators
+// would take four times as many statements as one class needs, with
+// little incremental effect on bloat.
+
+template<typename Number, typename Trammel>
+bool operator==(Number n, tn_range<Number,Trammel> const& z)
+{
+    return z.operator==(n);
+}
+
+template<typename Number, typename Trammel>
+bool operator==(std::string const& s, tn_range<Number,Trammel> const& z)
+{
+    return z.operator==(s);
+}
+
+template<typename Number, typename Trammel>
+bool operator!=(Number n, tn_range<Number,Trammel> const& z)
+{
+    return !z.operator==(n);
+}
+
+template<typename Number, typename Trammel>
+bool operator!=(std::string const& s, tn_range<Number,Trammel> const& z)
+{
+    return !z.operator==(s);
+}
+
 #endif // tn_range_hpp
 
diff --git a/tn_range.tpp b/tn_range.tpp
index 1eea4ce..a1587a5 100644
--- a/tn_range.tpp
+++ b/tn_range.tpp
@@ -524,6 +524,24 @@ bool tn_range<Number,Trammel>::operator==(std::string 
const& s) const
 }
 
 template<typename Number, typename Trammel>
+bool tn_range<Number,Trammel>::operator!=(tn_range<Number,Trammel> const& z) 
const
+{
+    return !operator==(z);
+}
+
+template<typename Number, typename Trammel>
+bool tn_range<Number,Trammel>::operator!=(Number n) const
+{
+    return !operator==(n);
+}
+
+template<typename Number, typename Trammel>
+bool tn_range<Number,Trammel>::operator!=(std::string const& s) const
+{
+    return !operator==(s);
+}
+
+template<typename Number, typename Trammel>
 bool tn_range<Number,Trammel>::operator<(tn_range<Number,Trammel> const& z) 
const
 {
     return value_ < z.value_;
diff --git a/tn_range_test.cpp b/tn_range_test.cpp
index 154fa43..75ff60c 100644
--- a/tn_range_test.cpp
+++ b/tn_range_test.cpp
@@ -250,7 +250,7 @@ void tn_range_test::test_percentages(char const* file, int 
line)
 
     T t_percentage;
     t_percentage = 50;
-    INVOKE_BOOST_TEST_EQUAL(50, t_percentage, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(50), t_percentage, file, line);
 
     INVOKE_BOOST_TEST(!t_percentage.is_valid( n1), file, line);
     INVOKE_BOOST_TEST( t_percentage.is_valid(  0), file, line);
@@ -274,26 +274,26 @@ void tn_range_test::test_percentages(char const* file, 
int line)
     INVOKE_BOOST_TEST_EQUAL(t_percentage.curb(101), 100, file, line);
 
     T t0(n10);
-    INVOKE_BOOST_TEST_EQUAL(  0, t0, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(  0), t0, file, line);
     T t1(  0);
-    INVOKE_BOOST_TEST_EQUAL(  0, t1, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(  0), t1, file, line);
     T t2(  1);
-    INVOKE_BOOST_TEST_EQUAL(  1, t2, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(  1), t2, file, line);
     T t3(100);
-    INVOKE_BOOST_TEST_EQUAL(100, t3, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(100), t3, file, line);
     T t4(101);
-    INVOKE_BOOST_TEST_EQUAL(100, t4, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(100), t4, file, line);
 
     t_percentage = n10;
-    INVOKE_BOOST_TEST_EQUAL(  0, t_percentage, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(  0), t_percentage, file, line);
     t_percentage =   0;
-    INVOKE_BOOST_TEST_EQUAL(  0, t_percentage, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(  0), t_percentage, file, line);
     t_percentage =   1;
-    INVOKE_BOOST_TEST_EQUAL(  1, t_percentage, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(  1), t_percentage, file, line);
     t_percentage = 100;
-    INVOKE_BOOST_TEST_EQUAL(100, t_percentage, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(100), t_percentage, file, line);
     t_percentage = 101;
-    INVOKE_BOOST_TEST_EQUAL(100, t_percentage, file, line);
+    INVOKE_BOOST_TEST_EQUAL(N(100), t_percentage, file, line);
 }
 
 void tn_range_test::test()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]