lmi-commits
[Top][All Lists]
Advanced

[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))



reply via email to

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