lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] valyuta/002 5fb74f1 7/7: Prefer cents() to m()


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/002 5fb74f1 7/7: Prefer cents() to m()
Date: Sun, 20 Sep 2020 18:51:24 -0400 (EDT)

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

    Prefer cents() to m()
    
    "m()" suggests that read access to a private member is being given.
    "cents()" suggests that the internal state is returned as cents.
    It's just a matter of connotation, but connotations matter.
    
    Incidentally split excessively long lines--those resulting from
    s/m/cents/, and one other.
---
 currency.hpp | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/currency.hpp b/currency.hpp
index 3a38fda..6090009 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -109,10 +109,11 @@ class currency
     // highly unlikely to overflow on multiplication by an int.
     currency const& operator*=(int z) {m_ *= z; return *this;}
 
-    data_type m() const {return m_;} // restrict to friends?
+    data_type cents() const {return m_;}
 
   private:
-    data_type from_int(int i) const {return cents_per_dollar * 
bourn_cast<data_type>(i);}
+    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:
@@ -148,12 +149,18 @@ 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, currency const& rhs)
+    {return lhs.cents() == rhs.cents();}
+inline bool operator< (currency const& lhs, currency const& rhs)
+    {return lhs.cents() <  rhs.cents();}
+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 currency operator+(currency lhs, currency rhs) {return lhs += rhs;}
 inline currency operator-(currency lhs, currency rhs) {return lhs -= rhs;}



reply via email to

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