lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] valyuta/002 d8e2470 15/21: Refactor for clarity


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/002 d8e2470 15/21: Refactor for clarity
Date: Fri, 18 Sep 2020 21:53:49 -0400 (EDT)

branch: valyuta/002
commit d8e24703c4f9017f781889b73b41fe7ec9b04589
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Refactor for clarity
---
 currency.hpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/currency.hpp b/currency.hpp
index ca6cd74..9c95310 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -77,9 +77,11 @@ class currency
     currency(currency const&) = default;
     ~currency() = default;
 
-    explicit currency(double    d) : m_ {from_double(d)}           {}
-    explicit currency(int       i) : m_ {cents_per_dollar * 
bourn_cast<data_type>(i)} {}
-    explicit currency(data_type i, bool) : m_ {i} {}
+    // The extra, ignored argument ensures that this special-purpose
+    // ctor ambiguates no other.
+    explicit currency(data_type c, bool) : m_ {c} {}
+    explicit currency(double    d)       : m_ {from_double(d)} {}
+    explicit currency(int       i)       : m_ {from_int   (i)} {}
 
     currency& operator=(currency const&) = default;
 
@@ -114,6 +116,7 @@ class currency
     data_type m() const {return m_;} // restrict to friends?
 
   private:
+    data_type from_int(int i) const {return cents_per_dollar * 
bourn_cast<data_type>(i);}
     // Want something just slightly more permissive:
 //  data_type from_double(double d) const {return bourn_cast<data_type>(100.0 
* d);}
     // Far too permissive:



reply via email to

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