lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] valyuta/005 2aae91a 14/17: Improve incrementally


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/005 2aae91a 14/17: Improve incrementally
Date: Sat, 16 Jan 2021 21:06:19 -0500 (EST)

branch: valyuta/005
commit 2aae91ae5e830e0021bf4ba99ac9b112e08719c2
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Improve incrementally
---
 currency.hpp | 19 +++++++++----------
 round_to.hpp |  4 ++--
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/currency.hpp b/currency.hpp
index 917fd66..bdd5c4b 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -37,7 +37,7 @@ class raw_cents {}; // Tag class.
 class LMI_SO currency
 {
     friend class currency_test;
-    template<typename T> friend class round_to;
+    template<typename> friend class round_to;
     friend class round_to_test;
 #if defined CURRENCY_UNIT_IS_CENTS
     static constexpr int    cents_digits     = 2;
@@ -57,19 +57,16 @@ class LMI_SO currency
     currency& operator+=(currency const& z) {m_ += z.m_; return *this;}
     currency& operator-=(currency const& z) {m_ -= z.m_; return *this;}
 
-    currency& operator*=(int z)             {m_ *= z   ; return *this;}
+    currency& operator*=(int             z) {m_ *= z   ; return *this;}
 
     data_type cents() const {return m_;}
     // !! possible underflow?
     double d() const {return m_ / cents_per_dollar;}
 
   private:
-    data_type m_ = {0};
+    data_type m_ = {};
 };
 
-inline currency operator-(currency const& z)
-    {return currency(-z.cents(), raw_cents {});}
-
 inline bool operator==(currency const& lhs, currency const& rhs)
     {return lhs.cents() == rhs.cents();}
 inline bool operator< (currency const& lhs, currency const& rhs)
@@ -83,6 +80,9 @@ inline bool operator<=(currency const& lhs, currency const& 
rhs)
 inline bool operator>=(currency const& lhs, currency const& rhs)
     {return !operator< (lhs, rhs);}
 
+inline currency operator-(currency const& z)
+    {return currency(-z.cents(), raw_cents {});}
+
 inline currency operator+(currency const& lhs, currency const& rhs)
     {return currency {lhs} += rhs;}
 inline currency operator-(currency const& lhs, currency const& rhs)
@@ -101,9 +101,7 @@ inline double operator/(currency const& lhs, double rhs)
     {return lhs.d() / rhs;}
 
 inline std::ostream& operator<<(std::ostream& os, currency const& z)
-{
-    return os << z.d();
-}
+    {return os << z.d();}
 
 inline std::vector<double> doubleize(std::vector<currency> const& z)
 {
@@ -111,7 +109,7 @@ inline std::vector<double> doubleize(std::vector<currency> 
const& z)
     r.reserve(z.size());
     for(auto const& i : z)
         {
-        r.push_back(i.d());
+        r.emplace_back(i.d());
         }
     return r;
 }
@@ -125,4 +123,5 @@ inline std::vector<double> doubleize(std::vector<currency> 
const& z)
 /// the capital letter looks kind of like a "0".
 
 inline constexpr currency C0 = {};
+
 #endif // currency_hpp
diff --git a/round_to.hpp b/round_to.hpp
index 3788a5b..3ab8adb 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -270,7 +270,7 @@ class round_to
     currency c(RealType r) const;
     std::vector<currency> c(std::vector<RealType> r) const;
 
-    currency c(currency z) const;
+    currency c(currency const& z) const;
 
     int decimals() const;
     rounding_style style() const;
@@ -402,7 +402,7 @@ inline std::vector<currency> 
round_to<RealType>::c(std::vector<RealType> r) cons
 
 // !! need unit tests
 template<typename RealType>
-inline currency round_to<RealType>::c(currency z) const
+inline currency round_to<RealType>::c(currency const& z) const
 {
 #if defined CURRENCY_UNIT_IS_CENTS
     return (decimals_ < currency::cents_digits) ? c(z.d()) : z;



reply via email to

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