[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/002 ba6a8d1 31/65: implement currency compar
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/002 ba6a8d1 31/65: implement currency comparisons as free functions |
Date: |
Wed, 16 Sep 2020 16:55:16 -0400 (EDT) |
branch: valyuta/002
commit ba6a8d10c2bb8d565e839fbd715f0d663f925eac
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
implement currency comparisons as free functions
---
currency.hpp | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/currency.hpp b/currency.hpp
index df93967..9c5c2b3 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -74,6 +74,7 @@ class currency
operator double() const {return to_double();}
double d() const {return to_double();}
+#if 0
// Is this better, with 'const&'?
// bool operator==(currency const& z) const {return z.m_ == m_;}
@@ -90,6 +91,7 @@ class currency
bool operator!=(double d) const {return to_double() != d;}
bool operator> (double d) const {return to_double() > d;}
bool operator>=(double d) const {return to_double() >= d;}
+#endif // 0
// Is this the ideal signature for this operator?
// currency operator-() const {return currency(-m_);}
@@ -144,6 +146,45 @@ class currency
data_type m_ = {0};
};
+inline bool operator==(currency const& lhs, currency const& rhs){return
lhs.m() == rhs.m();}
+inline bool operator< (currency const& lhs, currency const& rhs){return
lhs.m() < rhs.m();}
+inline bool operator!=(currency const& lhs, currency const& rhs){return
!operator==(lhs,rhs);}
+inline bool operator> (currency const& lhs, currency const& rhs){return
operator< (rhs,lhs);}
+inline bool operator<=(currency const& lhs, currency const& rhs){return
!operator> (lhs,rhs);}
+inline bool operator>=(currency const& lhs, currency const& rhs){return
!operator< (lhs,rhs);}
+
+inline bool operator==(currency const& lhs, int const& rhs){return
lhs.m() == rhs;}
+inline bool operator< (currency const& lhs, int const& rhs){return
lhs.m() < rhs;}
+inline bool operator==(int const& lhs, currency const& rhs){return lhs ==
rhs.m();}
+inline bool operator< (int const& lhs, currency const& rhs){return lhs <
rhs.m();}
+
+inline bool operator!=(currency const& lhs, int const& rhs){return
!operator==(lhs,rhs);}
+inline bool operator> (currency const& lhs, int const& rhs){return
operator< (rhs,lhs);}
+inline bool operator<=(currency const& lhs, int const& rhs){return
!operator> (lhs,rhs);}
+inline bool operator>=(currency const& lhs, int const& rhs){return
!operator< (lhs,rhs);}
+
+inline bool operator!=(int const& lhs, currency const& rhs){return
!operator==(lhs,rhs);}
+inline bool operator> (int const& lhs, currency const& rhs){return
operator< (rhs,lhs);}
+inline bool operator<=(int const& lhs, currency const& rhs){return
!operator> (lhs,rhs);}
+inline bool operator>=(int const& lhs, currency const& rhs){return
!operator< (lhs,rhs);}
+
+// double--avoid these:
+
+inline bool operator==(currency const& lhs, double const& rhs){return
lhs.d() == rhs;}
+inline bool operator< (currency const& lhs, double const& rhs){return
lhs.d() < rhs;}
+inline bool operator==(double const& lhs, currency const& rhs){return lhs ==
rhs.d();}
+inline bool operator< (double const& lhs, currency const& rhs){return lhs <
rhs.d();}
+
+inline bool operator!=(currency const& lhs, double const& rhs){return
!operator==(lhs,rhs);}
+inline bool operator> (currency const& lhs, double const& rhs){return
operator< (rhs,lhs);}
+inline bool operator<=(currency const& lhs, double const& rhs){return
!operator> (lhs,rhs);}
+inline bool operator>=(currency const& lhs, double const& rhs){return
!operator< (lhs,rhs);}
+
+inline bool operator!=(double const& lhs, currency const& rhs){return
!operator==(lhs,rhs);}
+inline bool operator> (double const& lhs, currency const& rhs){return
operator< (rhs,lhs);}
+inline bool operator<=(double const& lhs, currency const& rhs){return
!operator> (lhs,rhs);}
+inline bool operator>=(double const& lhs, currency const& rhs){return
!operator< (lhs,rhs);}
+
inline currency operator+(currency lhs, currency rhs) {return lhs += rhs;}
inline currency operator-(currency lhs, currency rhs) {return lhs -= rhs;}
inline currency operator+(currency lhs, double rhs) {return lhs +=
currency(rhs);}
- [lmi-commits] [lmi] valyuta/002 8fd00bb 34/65: rework operator*(), (continued)
- [lmi-commits] [lmi] valyuta/002 8fd00bb 34/65: rework operator*(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 bf1943b 03/65: reformat, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 7481c2b 09/65: discard--throwaway assertions, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 998fdf5 35/65: operator/(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 c105c78 29/65: Currency: implement binary operator-, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 9cf4517 46/65: c(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 9da6616 55/65: Round explicitly in a few more cases, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 0e8c429 12/65: rounding, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 794727e 22/65: Round when converting from double to currency, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 d137177 02/65: Currency, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 ba6a8d1 31/65: implement currency comparisons as free functions,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/002 28a5e54 39/65: make data_type public, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 e9f5447 30/65: round currency to currency? huh?, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 90773f3 47/65: currency() rather than currency(0.0), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 5f00c5a 43/65: Add a commented-out idea, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 2dabfcf 62/65: Try to make something a little less arcane, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 9433c8e 65/65: Discuss timing, and philosophical and political questions, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 9bee994 19/65: use currency type, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 0bf83a4 18/65: augment, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 615a24c 48/65: round.c(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 9a4b91d 51/65: Speed measurements, Greg Chicares, 2020/09/16