[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/002 8fd00bb 34/65: rework operator*()
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/002 8fd00bb 34/65: rework operator*() |
Date: |
Wed, 16 Sep 2020 16:55:17 -0400 (EDT) |
branch: valyuta/002
commit 8fd00bbc27eb317fd9370ba2f780ad8015007f17
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
rework operator*()
---
currency.hpp | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/currency.hpp b/currency.hpp
index 9c5c2b3..66db12e 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -113,9 +113,9 @@ class currency
// Far too permissive:
// currency& operator*=(double z) {m_ = static_cast<data_type>(100.0 *
to_double() * z); return *this;}
// wrong: doesn't affect '*this'
- double operator*=(double z) {return to_double() * z;}
+// double operator*=(double z) {return to_double() * z;}
// Dangerous--can somehow take the place of operator*(double)
-// currency const& operator*=(int z) {m_ *= z; return *this;}
+ currency const& operator*=(int z) {m_ *= z; return *this;}
data_type m() const {return m_;} // restrict to friends?
@@ -191,7 +191,11 @@ inline currency operator+(currency lhs, double rhs)
{return lhs += currency(rhs)
inline currency operator-(currency lhs, double rhs) {return lhs -=
currency(rhs);}
//inline currency operator*(currency lhs, double rhs) {return lhs *=
currency(rhs);}
////inline double operator*(currency lhs, double rhs) {return lhs *=
currency(rhs);}
-inline double operator*(currency lhs, double rhs) {return lhs.operator*=(rhs);}
+// Don't actually want any member operator*() for double:
+inline double operator*(currency lhs, double rhs) {return lhs.d() * rhs;}
+inline double operator*(double lhs, currency rhs) {return lhs * rhs.d();}
+inline currency operator*(currency lhs, int rhs) {return lhs *= rhs;}
+inline currency operator*(int lhs, currency rhs) {return rhs *= lhs;}
//inline currency operator*(currency lhs, int rhs) {return lhs *= rhs;}
//inline currency operator*(int lhs, currency rhs) {return rhs *= lhs;}
- [lmi-commits] [lmi] valyuta/002 03262ae 16/65: commented-out curiosity, (continued)
- [lmi-commits] [lmi] valyuta/002 03262ae 16/65: commented-out curiosity, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 d63c5b3 33/65: round all the things, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 39eb954 36/65: symmetric binary operators, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 6381b2f 44/65: Throw on overflow, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 e0c5136 45/65: improve documentation, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 7bac50c 50/65: default-initialize currency, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 f7f87b2 42/65: unit test: overflow, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 9ea1df7 54/65: further improve preceding commit, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 ba43414 61/65: Record 64-bit timings, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 fb82290 63/65: Use maximal 64-bit rather than 32-bit integer value, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 8fd00bb 34/65: rework operator*(),
Greg Chicares <=
- [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, 2020/09/16