lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 3df7c5f 5/5: Prefer 'constexpr int' to 'enum'


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 3df7c5f 5/5: Prefer 'constexpr int' to 'enum' for independent constants
Date: Tue, 9 Nov 2021 15:03:45 -0500 (EST)

branch: master
commit 3df7c5fb6a7631fa721b4a7c5460f746514ec659
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Prefer 'constexpr int' to 'enum' for independent constants
---
 calendar_date.hpp     | 10 ++++------
 census_view.cpp       |  4 ++--
 cso_table.cpp         | 20 +++++++++-----------
 dbindex.hpp           | 42 ++++++++++++++++++------------------------
 ledger_invariant.cpp  | 13 ++++++-------
 progress_meter_wx.cpp | 17 ++++++++---------
 6 files changed, 47 insertions(+), 59 deletions(-)

diff --git a/calendar_date.hpp b/calendar_date.hpp
index d40fbca..d9959c9 100644
--- a/calendar_date.hpp
+++ b/calendar_date.hpp
@@ -124,12 +124,10 @@ LMI_SO jdn_t YmdToJdn(ymd_t);
 class LMI_SO calendar_date
 {
   public:
-    enum
-        {gregorian_epoch_jdn = 2361222
-        ,last_yyyy_date_jdn  = 5373484
-        ,min_verified_jdn    = 1721120
-        ,max_verified_jdn    = 9999999
-        };
+    static constexpr int gregorian_epoch_jdn {2361222};
+    static constexpr int last_yyyy_date_jdn  {5373484};
+    static constexpr int min_verified_jdn    {1721120};
+    static constexpr int max_verified_jdn    {9999999};
 
     calendar_date();
     explicit calendar_date(jdn_t);
diff --git a/census_view.cpp b/census_view.cpp
index 35cffe3..014eb55 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -1853,8 +1853,8 @@ void CensusView::UponPasteCensus(wxCommandEvent&)
             {
             if(exact_cast<tnr_date>(current_cell[headers[j]]))
                 {
-                static int const jdn_min = calendar_date::gregorian_epoch_jdn;
-                static int const jdn_max = calendar_date::last_yyyy_date_jdn;
+                int constexpr jdn_min = calendar_date::gregorian_epoch_jdn;
+                int constexpr jdn_max = calendar_date::last_yyyy_date_jdn;
                 static int const ymd_min = JdnToYmd(jdn_t(jdn_min)).value();
                 static int const ymd_max = JdnToYmd(jdn_t(jdn_max)).value();
                 int z = value_cast<int>(values[j]);
diff --git a/cso_table.cpp b/cso_table.cpp
index 77b55e1..1189624 100644
--- a/cso_table.cpp
+++ b/cso_table.cpp
@@ -28,17 +28,15 @@
 
 #include <algorithm>                    // count()
 
-enum
-    {cso_n_alb_or_anb =   2
-    ,cso_n_gender     =   3
-    ,cso_n_smoking    =   3
-    ,cso_omega_1980   = 100
-    ,cso_omega_2001   = 121
-    ,cso_omega_2017   = 121
-    ,cso_sns_age_1980 =  15
-    ,cso_sns_age_2001 =  16
-    ,cso_sns_age_2017 =  18
-    };
+constexpr int cso_n_alb_or_anb {  2};
+constexpr int cso_n_gender     {  3};
+constexpr int cso_n_smoking    {  3};
+constexpr int cso_omega_1980   {100};
+constexpr int cso_omega_2001   {121};
+constexpr int cso_omega_2017   {121};
+constexpr int cso_sns_age_1980 { 15};
+constexpr int cso_sns_age_2001 { 16};
+constexpr int cso_sns_age_2017 { 18};
 
 /// 1980 CSO
 
diff --git a/dbindex.hpp b/dbindex.hpp
index d21c9e1..844f329 100644
--- a/dbindex.hpp
+++ b/dbindex.hpp
@@ -31,36 +31,30 @@
 
 /// Number of database axes, excluding the special duration axis.
 
-enum
-    {number_of_indices = 6
-    };
+constexpr int number_of_indices {6};
 
 /// Ordered database axes.
 
-enum
-    {e_axis_gender    = 0
-    ,e_axis_uw_class  = 1
-    ,e_axis_smoking   = 2
-    ,e_axis_issue_age = 3
-    ,e_axis_uw_basis  = 4
-    ,e_axis_state     = 5
-    ,e_axis_duration  = 6
-    };
-
-/// These enumerators facilitate compile-time assertions in the
+constexpr int e_axis_gender    {0};
+constexpr int e_axis_uw_class  {1};
+constexpr int e_axis_smoking   {2};
+constexpr int e_axis_issue_age {3};
+constexpr int e_axis_uw_basis  {4};
+constexpr int e_axis_state     {5};
+constexpr int e_axis_duration  {6};
+
+/// These constants facilitate compile-time assertions in the
 /// product-database GUI, q.v.: an array cannot be indexed to
 /// produce an arithmetic constant expression [5.19/3].
 
-enum enum_database_dimensions
-    {e_number_of_axes    = 1 + number_of_indices
-    ,e_max_dim_gender    =   3
-    ,e_max_dim_uw_class  =   4
-    ,e_max_dim_smoking   =   3
-    ,e_max_dim_issue_age = 100
-    ,e_max_dim_uw_basis  =   5
-    ,e_max_dim_state     =  53
-    ,e_max_dim_duration  = 100
-    };
+constexpr int e_number_of_axes    {1 + number_of_indices};
+constexpr int e_max_dim_gender    {  3};
+constexpr int e_max_dim_uw_class  {  4};
+constexpr int e_max_dim_smoking   {  3};
+constexpr int e_max_dim_issue_age {100};
+constexpr int e_max_dim_uw_basis  {  5};
+constexpr int e_max_dim_state     { 53};
+constexpr int e_max_dim_duration  {100};
 
 /// Product-database lookup index.
 ///
diff --git a/ledger_invariant.cpp b/ledger_invariant.cpp
index 9364a60..43fe584 100644
--- a/ledger_invariant.cpp
+++ b/ledger_invariant.cpp
@@ -25,6 +25,7 @@
 
 #include "assert_lmi.hpp"
 #include "bourn_cast.hpp"
+#include "calendar_date.hpp"            // gregorian_epoch_jdn
 #include "contains.hpp"
 #include "crc32.hpp"
 #include "financial.hpp"                // for CalculateIrrs()
@@ -527,13 +528,11 @@ void LedgerInvariant::Init()
     WriteTsvFile               = false;
     SupplementalReport         = true;
 
-    // Probably this should be an "oecumenic" constant.
-    constexpr int gregorian_epoch_jdn {2361222};
-    EffDateJdn                 = gregorian_epoch_jdn;
-    DateOfBirthJdn             = gregorian_epoch_jdn;
-    LastCoiReentryDateJdn      = gregorian_epoch_jdn;
-    ListBillDateJdn            = gregorian_epoch_jdn;
-    InforceAsOfDateJdn         = gregorian_epoch_jdn;
+    EffDateJdn                 = calendar_date::gregorian_epoch_jdn;
+    DateOfBirthJdn             = calendar_date::gregorian_epoch_jdn;
+    LastCoiReentryDateJdn      = calendar_date::gregorian_epoch_jdn;
+    ListBillDateJdn            = calendar_date::gregorian_epoch_jdn;
+    InforceAsOfDateJdn         = calendar_date::gregorian_epoch_jdn;
 
     // Private internals.
 
diff --git a/progress_meter_wx.cpp b/progress_meter_wx.cpp
index 422e938..ef339f4 100644
--- a/progress_meter_wx.cpp
+++ b/progress_meter_wx.cpp
@@ -45,15 +45,14 @@ namespace
 class concrete_progress_meter
     :public progress_meter
 {
-    enum
-        {progress_dialog_style =
-                wxPD_APP_MODAL
-            |   wxPD_AUTO_HIDE
-            |   wxPD_CAN_ABORT
-            |   wxPD_ELAPSED_TIME
-            |   wxPD_ESTIMATED_TIME
-            |   wxPD_REMAINING_TIME
-            |   wxPD_SMOOTH
+    static constexpr int progress_dialog_style
+        {   wxPD_APP_MODAL
+        |   wxPD_AUTO_HIDE
+        |   wxPD_CAN_ABORT
+        |   wxPD_ELAPSED_TIME
+        |   wxPD_ESTIMATED_TIME
+        |   wxPD_REMAINING_TIME
+        |   wxPD_SMOOTH
         };
 
   public:



reply via email to

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