[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;
- [lmi-commits] [lmi] valyuta/005 7d6e748 02/17: Improve currency class and unit tests, (continued)
- [lmi-commits] [lmi] valyuta/005 7d6e748 02/17: Improve currency class and unit tests, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 4902da4 01/17: Reinvent currency ab ovo, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 ffa2ce4 09/17: Redesign unit test, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 90d7483 10/17: Improve currency class, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 3d44f42 13/17: Save a sorted list of regressions, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 c8864d3 04/17: Add commented-out relops, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 f3219f8 12/17: Use CURRENCY_UNIT_IS_CENTS appropriately, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 aad51dd 07/17: Inline more, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 b852a68 05/17: Add features, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 d69f05c 06/17: Ratify some regression-testing differences, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 2aae91a 14/17: Improve incrementally,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/005 0735250 15/17: Improve incrementally, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 dfdbf3c 16/17: Use currency type for class members as appropriate, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 221c094 08/17: Prefer constexpr, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 4401725 17/17: Merge branch 'master' into valyuta/005, Greg Chicares, 2021/01/16
- [lmi-commits] [lmi] valyuta/005 e3f3eff 11/17: Revert "Ratify some regression-testing differences", Greg Chicares, 2021/01/16