lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] valyuta/002 d9d16ef 3/5: Prefer a tag class to an ig


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/002 d9d16ef 3/5: Prefer a tag class to an ignored bool argument
Date: Sun, 20 Sep 2020 12:55:18 -0400 (EDT)

branch: valyuta/002
commit d9d16ef3ca068ff706d2bcd94efe5a4f2fd0c0e3
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Prefer a tag class to an ignored bool argument
---
 currency.hpp    | 10 ++++++----
 ihs_acctval.cpp |  4 ++--
 ihs_avmly.cpp   |  4 ++--
 ihs_avsolve.cpp |  2 +-
 round_to.hpp    |  4 ++--
 5 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/currency.hpp b/currency.hpp
index c843446..3a38fda 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -52,6 +52,8 @@
 #   endif // defined __GNUC__
 #endif // !CURRENCY_HAS_INTEGER_DATATYPE
 
+class raw_cents {}; // Tag class.
+
 class currency
 {
     friend std::ostream& operator<<(std::ostream&, currency const&);
@@ -79,16 +81,16 @@ class currency
 
     // The extra, ignored argument ensures that this special-purpose
     // ctor ambiguates no other.
-    explicit currency(data_type c, bool) : m_ {c} {}
-    explicit currency(double    d)       : m_ {from_double(d)} {}
-    explicit currency(int       i)       : m_ {from_int   (i)} {}
+    explicit currency(data_type c, raw_cents) : m_ {c} {}
+    explicit currency(double    d)            : m_ {from_double(d)} {}
+    explicit currency(int       i)            : m_ {from_int   (i)} {}
 
     currency& operator=(currency const&) = default;
 
     double d() const {return to_double();}
 
     // Is this the ideal signature for this operator?
-    currency operator-() const {return currency(-m_, true);}
+    currency operator-() const {return currency(-m_, raw_cents{});}
 
     currency& operator+=(currency z) {m_ += z.m_; return *this;}
     currency& operator-=(currency z) {m_ -= z.m_; return *this;}
diff --git a/ihs_acctval.cpp b/ihs_acctval.cpp
index 1b383e8..b162d1f 100644
--- a/ihs_acctval.cpp
+++ b/ihs_acctval.cpp
@@ -223,7 +223,7 @@ void AccountValue::SetGuarPrem()
         GuarPremium = SolveGuarPremium();
         }
     // bignum: the largest integer convertible to and from double.
-    LMI_ASSERT(GuarPremium < currency(1LL << 53, true));
+    LMI_ASSERT(GuarPremium < currency(1LL << 53, raw_cents{}));
     ledger_->SetGuarPremium(GuarPremium.d());
 }
 
@@ -617,7 +617,7 @@ void AccountValue::SetInitialValues()
     // which is the identity element for std::max(). Here, it's nearly
     // the equivalent for currency::data_type; dividing it by 101 is a
     // casual defense against commuting between dollars and cents.
-    HoneymoonValue = currency(-std::numeric_limits<currency::data_type>::max() 
/ 101, true);
+    HoneymoonValue = currency(-std::numeric_limits<currency::data_type>::max() 
/ 101, raw_cents{});
     if(mce_gen_curr == GenBasis_)
         {
         HoneymoonActive = yare_input_.HoneymoonEndorsement;
diff --git a/ihs_avmly.cpp b/ihs_avmly.cpp
index bac70cc..c95f930 100644
--- a/ihs_avmly.cpp
+++ b/ihs_avmly.cpp
@@ -1269,7 +1269,7 @@ void AccountValue::TxAscertainDesiredPayment()
 //  LMI_ASSERT(materially_equal(GrossPmts[Month], EeGrossPmts[Month] + 
ErGrossPmts[Month]));
     LMI_ASSERT(GrossPmts[Month] == EeGrossPmts[Month] + ErGrossPmts[Month]);
     // bignum: the largest integer convertible to and from double.
-    LMI_ASSERT(GrossPmts[Month] < currency(1LL << 53, true));
+    LMI_ASSERT(GrossPmts[Month] < currency(1LL << 53, raw_cents{}));
 
     if(0 == Year && 0 == Month)
         {
@@ -2065,7 +2065,7 @@ void AccountValue::TxTestHoneymoonForExpiration()
         // which is the identity element for std::max(). Here, it's nearly
         // the equivalent for currency::data_type; dividing it by 101 is a
         // casual defense against commuting between dollars and cents.
-        HoneymoonValue  = 
currency(-std::numeric_limits<currency::data_type>::max() / 101, true);
+        HoneymoonValue  = 
currency(-std::numeric_limits<currency::data_type>::max() / 101, raw_cents{});
         }
 }
 
diff --git a/ihs_avsolve.cpp b/ihs_avsolve.cpp
index 1e3103f..75aeb66 100644
--- a/ihs_avsolve.cpp
+++ b/ihs_avsolve.cpp
@@ -242,7 +242,7 @@ currency AccountValue::SolveTest(currency a_CandidateValue)
 
     if(mce_solve_for_non_mec == SolveTarget_)
         {
-        static const currency C1(100, true); // One hundred cents.
+        static const currency C1(100, raw_cents{}); // One hundred cents.
         return InvariantValues().IsMec ? -C1 : C1;
         }
 
diff --git a/round_to.hpp b/round_to.hpp
index 880d558..851c2c2 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -395,7 +395,7 @@ inline currency round_to<RealType>::c(RealType r) const
     RealType z = static_cast<RealType>
         (rounding_function_(static_cast<RealType>(r * scale_fwd_)) * 
scale_back_c_
         );
-    return currency(bourn_cast<currency::data_type>(z), true);
+    return currency(bourn_cast<currency::data_type>(z), raw_cents{});
 #if 0
     // don't do this in production:
     if(z != std::trunc(z))
@@ -404,7 +404,7 @@ inline currency round_to<RealType>::c(RealType r) const
             << trunc(z) << "\n"
             << LMI_FLUSH
             ;
-    currency k(bourn_cast<currency::data_type>(z), true);
+    currency k(bourn_cast<currency::data_type>(z), raw_cents);
     if(k.m() != bourn_cast<currency::data_type>(std::trunc(k.m())))
         warning()
             << k.m() << " does not equal\n"



reply via email to

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