[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/002 d837132 38/65: Overload currency ctor
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/002 d837132 38/65: Overload currency ctor |
Date: |
Wed, 16 Sep 2020 16:55:18 -0400 (EDT) |
branch: valyuta/002
commit d8371326798a512d3260f12ae09d84539355daf1
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Overload currency ctor
Overloads for double and long long int only create an ambiguity for an
int argument, which is prevented by overloading for int as well.
Overloading operator=() for int causes problems.
---
currency.hpp | 12 +++++++-----
round_to.hpp | 2 +-
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/currency.hpp b/currency.hpp
index 8f9857a..96f6705 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -63,13 +63,15 @@ class currency
currency(currency const&) = default;
~currency() = default;
- explicit currency(double d) {m_ = from_double(d);}
- // avoid troublesome overloads
- explicit currency(std::int64_t d, bool) {m_ = bourn_cast<data_type>(d);}
// instead: init-list
+ explicit currency(double d) : m_ {from_double(d)} {}
+ explicit currency(int i) : m_ {bourn_cast<data_type>(i)} {}
+ explicit currency(std::int64_t i) : m_ {bourn_cast<data_type>(i)} {}
currency& operator=(currency const&) = default;
- // IMPORTANT eventually suppress this?
- currency& operator=(double d) {m_ = from_double(d); return *this;}
+ // IMPORTANT eventually suppress this? or both of these?
+ // defining both causes real problems
+ currency& operator=(double d) {m_ = from_double(d); return
*this;}
+// currency& operator=(int i) {m_ = bourn_cast<data_type>(i); return
*this;}
operator double() const {return to_double();}
double d() const {return to_double();}
diff --git a/round_to.hpp b/round_to.hpp
index 629d12a..ebd8274 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -390,7 +390,7 @@ inline currency round_to<RealType>::c(RealType r) const
(rounding_function_(static_cast<RealType>(r * scale_fwd_)) *
scale_back_c_
);
// include required headers
- return currency(bourn_cast<std::int64_t>(z), true);
+ return currency(bourn_cast<std::int64_t>(z));
#if 0
// don't do this in production:
if(z != std::trunc(z))
- [lmi-commits] [lmi] branch valyuta/002 created (now 9433c8e), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 ef7fe2f 01/65: Change type of currency variables to 'currency' in headers, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 540c4f3 11/65: currency(0.0), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 e260d89 14/65: avoid operator double(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 deba50c 25/65: assert rounding to currency makes sense, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 7dc9331 32/65: round.c(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 915d111 26/65: avoid operator double(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 d837132 38/65: Overload currency ctor,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/002 5d2e8ec 49/65: prefer to avoid operator=(double)?, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 015253b 10/65: add an alternative, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 346c95b 05/65: improve, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 c4e0809 24/65: use round_to<>.c(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 360060c 21/65: suppress failing assertions, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 c407817 13/65: fix defect, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 0cd4c10 27/65: There can be no operator*, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 c34960b 17/65: alternative for debugging, Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 56ec06f 37/65: overload SetMonthlyDetail(), Greg Chicares, 2020/09/16
- [lmi-commits] [lmi] valyuta/002 518d684 28/65: Currency: implement binary operator+, Greg Chicares, 2020/09/16