lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 2ba6003 6/6: Dispense with smart pointers


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 2ba6003 6/6: Dispense with smart pointers
Date: Fri, 19 Oct 2018 15:45:07 -0400 (EDT)

branch: master
commit 2ba60032276da6d22bc484f48a09997685be1853
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Dispense with smart pointers
    
    std::unique_ptr<T> is movable even if T isn't. But if T can readily
    be made movable, then std::vector<std::unique_ptr<T>> isn't needed.
---
 account_value.hpp |  1 +
 basic_values.hpp  |  1 +
 group_values.cpp  | 83 +++++++++++++++++++++++++++----------------------------
 3 files changed, 42 insertions(+), 43 deletions(-)

diff --git a/account_value.hpp b/account_value.hpp
index 13206e7..b7d5551 100644
--- a/account_value.hpp
+++ b/account_value.hpp
@@ -56,6 +56,7 @@ class LMI_SO AccountValue
     enum {months_per_year = 12};
 
     explicit AccountValue(Input const& input);
+    AccountValue(AccountValue&&) = default;
     ~AccountValue() override = default;
 
     double RunAV                ();
diff --git a/basic_values.hpp b/basic_values.hpp
index da151aa..4524761 100644
--- a/basic_values.hpp
+++ b/basic_values.hpp
@@ -94,6 +94,7 @@ class LMI_SO BasicValues
         ,bool               a_AdbInForce
         ,double             a_TargetPremium
         );
+    BasicValues(BasicValues&&) = default;
     virtual ~BasicValues() = default;
 
     void Init();
diff --git a/group_values.cpp b/group_values.cpp
index b096902..38e22ec 100644
--- a/group_values.cpp
+++ b/group_values.cpp
@@ -43,9 +43,7 @@
 
 #include <algorithm>                    // max()
 #include <iterator>                     // back_inserter()
-#include <memory>                       // make_unique()
 #include <string>
-#include <utility>                      // move()
 
 namespace
 {
@@ -253,7 +251,7 @@ census_run_result run_census_in_parallel::operator()
 
     ledger_emitter emitter(file, emission);
 
-    std::vector<std::unique_ptr<AccountValue>> cell_values;
+    std::vector<AccountValue> cell_values;
     std::vector<mcenum_run_basis> const& RunBases = composite.GetRunBases();
 
     int const first_cell_inforce_year  = 
value_cast<int>((*cells.begin())["InforceYear"].str());
@@ -269,9 +267,8 @@ census_run_result run_census_in_parallel::operator()
             {
             { // Begin fenv_guard scope.
             fenv_guard fg;
-            auto z {std::make_unique<AccountValue>(ip)};
-            cell_values.push_back(std::move(z));
-            AccountValue& av = *cell_values.back();
+            cell_values.emplace_back(ip);
+            AccountValue& av = cell_values.back();
 
             std::string const name(cells[j]["InsuredName"].str());
             // Indexing: here, j is an index into cells, not cell_values.
@@ -349,8 +346,8 @@ census_run_result run_census_in_parallel::operator()
         int MaxYr = 0;
         for(auto& i : cell_values)
             {
-            i->InitializeLife(run_basis);
-            MaxYr = std::max(MaxYr, i->GetLength());
+            i.InitializeLife(run_basis);
+            MaxYr = std::max(MaxYr, i.GetLength());
             }
 
         meter = create_progress_meter
@@ -362,15 +359,15 @@ census_run_result run_census_in_parallel::operator()
         // Variables to support tiering and experience rating.
 
         double const case_ibnr_months =
-            cell_values[0]->ibnr_as_months_of_mortality_charges()
+            cell_values.front().ibnr_as_months_of_mortality_charges()
             ;
         double const case_experience_rating_amortization_years =
-            cell_values[0]->experience_rating_amortization_years()
+            cell_values.front().experience_rating_amortization_years()
             ;
 
         double case_accum_net_mortchgs = 0.0;
         double case_accum_net_claims   = 0.0;
-        double case_k_factor = 
cell_values[0]->yare_input_.ExperienceRatingInitialKFactor;
+        double case_k_factor = 
cell_values.front().yare_input_.ExperienceRatingInitialKFactor;
 
         // Experience rating as implemented here uses either a special
         // scalar input rate, or the separate-account rate. Those
@@ -380,16 +377,16 @@ census_run_result run_census_in_parallel::operator()
 
         std::vector<double> experience_reserve_rate;
         std::copy
-            (cell_values[0]->yare_input_.SeparateAccountRate.begin()
-            ,cell_values[0]->yare_input_.SeparateAccountRate.end()
+            (cell_values.front().yare_input_.SeparateAccountRate.begin()
+            ,cell_values.front().yare_input_.SeparateAccountRate.end()
             ,std::back_inserter(experience_reserve_rate)
             );
         experience_reserve_rate.resize(MaxYr, experience_reserve_rate.back());
-        if(cell_values[0]->yare_input_.OverrideExperienceReserveRate)
+        if(cell_values.front().yare_input_.OverrideExperienceReserveRate)
             {
             experience_reserve_rate.assign
                 (experience_reserve_rate.size()
-                ,cell_values[0]->yare_input_.ExperienceReserveRate
+                ,cell_values.front().yare_input_.ExperienceReserveRate
                 );
             }
 
@@ -404,13 +401,13 @@ census_run_result run_census_in_parallel::operator()
                 {
                 // A cell must be initialized at the beginning of any
                 // partial inforce year in which it's illustrated.
-                if(i->PrecedesInforceDuration(year, 11))
+                if(i.PrecedesInforceDuration(year, 11))
                     {
                     continue;
                     }
-                i->Year = year;
-                i->CoordinateCounters();
-                i->InitializeYear();
+                i.Year = year;
+                i.CoordinateCounters();
+                i.InitializeYear();
                 }
 
             // Process one month at a time for all cells.
@@ -429,24 +426,24 @@ census_run_result run_census_in_parallel::operator()
                 // Process transactions through monthly deduction.
                 for(auto& i : cell_values)
                     {
-                    if(i->PrecedesInforceDuration(year, month))
+                    if(i.PrecedesInforceDuration(year, month))
                         {
                         continue;
                         }
-                    i->Month = month;
-                    i->CoordinateCounters();
-                    i->IncrementBOM(year, month, case_k_factor);
-                    assets += i->GetSepAcctAssetsInforce();
+                    i.Month = month;
+                    i.CoordinateCounters();
+                    i.IncrementBOM(year, month, case_k_factor);
+                    assets += i.GetSepAcctAssetsInforce();
                     }
 
                 // Process transactions from int credit through end of month.
                 for(auto& i : cell_values)
                     {
-                    if(i->PrecedesInforceDuration(year, month))
+                    if(i.PrecedesInforceDuration(year, month))
                         {
                         continue;
                         }
-                    i->IncrementEOM(year, month, assets, i->CumPmts);
+                    i.IncrementEOM(year, month, assets, i.CumPmts);
                     }
                 }
 
@@ -467,17 +464,17 @@ census_run_result run_census_in_parallel::operator()
             double projected_net_mortchgs = 0.0;
             for(auto& i : cell_values)
                 {
-                if(i->PrecedesInforceDuration(year, 11))
+                if(i.PrecedesInforceDuration(year, 11))
                     {
                     continue;
                     }
-                i->SetClaims();
-                i->SetProjectedCoiCharge();
-                eoy_inforce_lives      += i->InforceLivesEoy();
-                i->IncrementEOY(year);
-                years_net_claims       += i->GetCurtateNetClaimsInforce();
-                years_net_mortchgs     += i->GetCurtateNetCoiChargeInforce();
-                projected_net_mortchgs += i->GetProjectedCoiChargeInforce();
+                i.SetClaims();
+                i.SetProjectedCoiCharge();
+                eoy_inforce_lives      += i.InforceLivesEoy();
+                i.IncrementEOY(year);
+                years_net_claims       += i.GetCurtateNetClaimsInforce();
+                years_net_mortchgs     += i.GetCurtateNetCoiChargeInforce();
+                projected_net_mortchgs += i.GetProjectedCoiChargeInforce();
                 }
 
             // Calculate next year's k factor. Do this only for
@@ -511,7 +508,7 @@ census_run_result run_census_in_parallel::operator()
 
             if(first_cell_inforce_year == year)
                 {
-                case_accum_net_mortchgs += 
cell_values[0]->yare_input_.InforceNetExperienceReserve;
+                case_accum_net_mortchgs += 
cell_values.front().yare_input_.InforceNetExperienceReserve;
                 }
 
             // Apportion experience-rating reserve uniformly across
@@ -524,14 +521,14 @@ census_run_result run_census_in_parallel::operator()
             // equal the original total reserve.
 
             if
-                (   cell_values[0]->yare_input_.UseExperienceRating
+                (   cell_values.front().yare_input_.UseExperienceRating
                 &&  mce_gen_curr == expense_and_general_account_basis
                 &&  0.0 != eoy_inforce_lives
                 )
                 {
                 if(first_cell_inforce_year == year)
                     {
-                    years_net_mortchgs += 
cell_values[0]->yare_input_.InforceYtdNetCoiCharge;
+                    years_net_mortchgs += 
cell_values.front().yare_input_.InforceYtdNetCoiCharge;
                     }
                 double case_ibnr =
                         years_net_mortchgs
@@ -565,12 +562,12 @@ census_run_result run_census_in_parallel::operator()
                 double case_net_mortality_reserve_checksum = 0.0;
                 for(auto& i : cell_values)
                     {
-                    if(i->PrecedesInforceDuration(year, 11))
+                    if(i.PrecedesInforceDuration(year, 11))
                         {
                         continue;
                         }
                     case_net_mortality_reserve_checksum +=
-                        i->ApportionNetMortalityReserve
+                        i.ApportionNetMortalityReserve
                             (   case_net_mortality_reserve
                             /   eoy_inforce_lives
                             );
@@ -604,7 +601,7 @@ census_run_result run_census_in_parallel::operator()
 
         for(auto& i : cell_values)
             {
-            i->FinalizeLife(run_basis);
+            i.FinalizeLife(run_basis);
             }
 
         } // End fenv_guard scope.
@@ -618,8 +615,8 @@ census_run_result run_census_in_parallel::operator()
     for(auto& i : cell_values)
         {
         fenv_guard fg;
-        i->FinalizeLifeAllBases();
-        composite.PlusEq(*i->ledger_from_av());
+        i.FinalizeLifeAllBases();
+        composite.PlusEq(*i.ledger_from_av());
         if(!meter->reflect_progress())
             {
             result.completed_normally_ = false;
@@ -642,7 +639,7 @@ census_run_result run_census_in_parallel::operator()
         std::string const name(cells[j]["InsuredName"].str());
         result.seconds_for_output_ += emitter.emit_cell
             (serial_file_path(file, name, j, "hastur")
-            ,*i->ledger_from_av()
+            ,*i.ledger_from_av()
             );
         meter->dawdle(intermission_between_printouts(emission));
         if(!meter->reflect_progress())



reply via email to

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