lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 494c8c3 1/3: Modernize for statements


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 494c8c3 1/3: Modernize for statements
Date: Thu, 19 Jan 2017 09:27:46 +0000 (UTC)

branch: master
commit 494c8c37ac535c1f1966ddf17c92a2b8c300e624
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Modernize for statements
    
    This statement in the original:
      char const*const field = fields[j];
    was already not ideal because the Levenshtein distance between the
    variable names is so slight that it would be too easy to mistake one
    for the other. In assert_okay_to_run_group_quote() in particular, the
    simplest modernization would worsen that problem, producing
      for(auto const& cell : cells)
      for(auto const& field : fields)
    so the for-range-initializers have been given longer, more descriptive
    names.
---
 illustrator.cpp |   32 +++++++++++++++-----------------
 illustrator.hpp |    2 +-
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/illustrator.cpp b/illustrator.cpp
index 140fe1b..559d14a 100644
--- a/illustrator.cpp
+++ b/illustrator.cpp
@@ -33,7 +33,6 @@
 #include "handle_exceptions.hpp"
 #include "input.hpp"
 #include "ledgervalues.hpp"
-#include "miscellany.hpp"               // lmi_array_size()
 #include "multiple_cell_document.hpp"
 #include "path_utility.hpp"             // fs::path inserter
 #include "platform_dependent.hpp"       // access()
@@ -225,31 +224,32 @@ namespace
 
 void assert_consistent_run_order
     (Input              const& case_default
-    ,std::vector<Input> const& cells
+    ,std::vector<Input> const& all_cells
     )
 {
-    typedef std::vector<Input>::size_type svst;
-    for(svst i = 0; i != cells.size(); ++i)
+    int i = 0;
+    for(auto const& cell : all_cells)
         {
-        if(case_default["RunOrder"] != cells[i]["RunOrder"])
+        if(case_default["RunOrder"] != cell["RunOrder"])
             {
             fatal_error()
                 << "Case-default run order '"
                 << case_default["RunOrder"]
                 << "' differs from run order '"
-                << cells[i]["RunOrder"]
+                << cell["RunOrder"]
                 << "' of cell number "
                 << 1 + i
                 << ". Make this consistent before running illustrations."
                 << LMI_FLUSH
                 ;
             }
+        ++i;
         }
 }
 
 void assert_okay_to_run_group_quote
     (Input              const& case_default
-    ,std::vector<Input> const& cells
+    ,std::vector<Input> const& all_cells
     )
 {
     // There is a surjective mapping of the input fields listed here
@@ -270,7 +270,7 @@ void assert_okay_to_run_group_quote
     // products used with group quotes, spouse and child riders have
     // no maximum issue age.)
     //
-    static char const*const fields[] =
+    static char const*const group_quote_invariant_fields[] =
         {"ProductName"
         ,"CorporationName"
         ,"AgentName"
@@ -284,20 +284,17 @@ void assert_okay_to_run_group_quote
         ,"SpouseRider"
         ,"SpouseRiderAmount"
         };
-    static std::size_t const n = lmi_array_size(fields);
 
     if(case_default["EffectiveDate"] != case_default["InforceAsOfDate"])
         {
         fatal_error() << "Group quotes allowed for new business only." << 
LMI_FLUSH;
         }
 
-    typedef std::vector<Input>::size_type svst;
-    for(svst i = 0; i != cells.size(); ++i)
+    int i = 0;
+    for(auto const& cell : all_cells)
         {
-        Input const& cell = cells[i];
-        for(std::size_t j = 0; j != n; ++j)
+        for(auto const& field : group_quote_invariant_fields)
             {
-            char const*const field = fields[j];
             if(case_default[field] != cell[field])
                 {
                 fatal_error()
@@ -314,6 +311,7 @@ void assert_okay_to_run_group_quote
                     ;
                 }
             }
+        ++i;
         }
 }
 } // Unnamed namespace.
@@ -321,13 +319,13 @@ void assert_okay_to_run_group_quote
 void test_census_consensus
     (mcenum_emission           emission
     ,Input              const& case_default
-    ,std::vector<Input> const& cells
+    ,std::vector<Input> const& all_cells
     )
 {
-    assert_consistent_run_order(case_default, cells);
+    assert_consistent_run_order(case_default, all_cells);
     if(emission & mce_emit_group_quote)
         {
-        assert_okay_to_run_group_quote(case_default, cells);
+        assert_okay_to_run_group_quote(case_default, all_cells);
         }
 }
 
diff --git a/illustrator.hpp b/illustrator.hpp
index 56e206c..6d314e5 100644
--- a/illustrator.hpp
+++ b/illustrator.hpp
@@ -76,7 +76,7 @@ Input const& LMI_SO default_cell();
 void LMI_SO test_census_consensus
     (mcenum_emission           emission
     ,Input              const& case_default
-    ,std::vector<Input> const& cells
+    ,std::vector<Input> const& all_cells
     );
 
 #endif // illustrator_hpp



reply via email to

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