[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 23fe71f 11/14: Do away with an undesirable sm
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 23fe71f 11/14: Do away with an undesirable smart pointer [290] |
Date: |
Mon, 5 Apr 2021 18:26:47 -0400 (EDT) |
branch: master
commit 23fe71ffa85af986f900733035bf43d9acd89aaf
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Do away with an undesirable smart pointer [290]
Sometimes using unique_ptr simplifies the physical design by making a
header smaller after preprocessing. Here, the tradeoff was not clearly
favorable: including <memory>, which is not insignificant, vs. the
definitions of two tiny classes and a couple of minor headers. Using
unique_ptr had also required writing a defaulted dtor out of line, and
accessing members with '->' instead of the simpler '.'.
---
antediluvian_stubs.cpp | 2 --
ihs_irc7702.cpp | 75 +++++++++++++++++++-------------------------------
ihs_irc7702.hpp | 22 ++-------------
3 files changed, 30 insertions(+), 69 deletions(-)
diff --git a/antediluvian_stubs.cpp b/antediluvian_stubs.cpp
index 4bc260e..f240273 100644
--- a/antediluvian_stubs.cpp
+++ b/antediluvian_stubs.cpp
@@ -69,8 +69,6 @@ int FundData::GetNumberOfFunds() const
return 0;
}
-Irc7702::~Irc7702() = default;
-
gpt_server::gpt_server(mcenum_emission)
{}
diff --git a/ihs_irc7702.cpp b/ihs_irc7702.cpp
index d082059..480f51b 100644
--- a/ihs_irc7702.cpp
+++ b/ihs_irc7702.cpp
@@ -25,7 +25,6 @@
#include "alert.hpp"
#include "assert_lmi.hpp"
-#include "commutation_functions.hpp"
#include "et_vector.hpp"
#include "materially_equal.hpp"
#include "math_functions.hpp" // back_sum()
@@ -195,15 +194,6 @@ Irc7702::Irc7702
Init();
}
-/// Destructor.
-///
-/// Although it is explicitly defaulted, this destructor is not
-/// implemented inside the class definition, because the header
-/// forward-declares one or more classes that are held by
-/// std::unique_ptr, so their destructors are visible only here.
-
-Irc7702::~Irc7702() = default;
-
//============================================================================
void Irc7702::ProcessGptPmt
(int a_Duration
@@ -398,48 +388,39 @@ void Irc7702::Init()
InitPvVectors(Opt1Int4Pct);
InitPvVectors(Opt2Int4Pct);
InitPvVectors(Opt1Int6Pct);
- // TODO ?? We can delete the commutation functions here, rather than in
- // the dtor, to save some space. We defer doing so until the
- // program is complete. TAXATION !! It would be better not to use
pointers--see header.
}
//============================================================================
void Irc7702::InitCommFns()
{
// Commutation functions using min i = iglp(): both options 1 and 2
- CommFns[Opt1Int4Pct].reset
- (::new ULCommFns
- (Qc
- ,ic_glp_
- ,ig_glp_
- ,mce_option1_for_7702
- ,mce_monthly
- )
+ CommFns[Opt1Int4Pct] = ULCommFns
+ (Qc
+ ,ic_glp_
+ ,ig_glp_
+ ,mce_option1_for_7702
+ ,mce_monthly
);
- DEndt[Opt1Int4Pct] = CommFns[Opt1Int4Pct]->aDomega();
-
- CommFns[Opt2Int4Pct].reset
- (::new ULCommFns
- (Qc
- ,ic_glp_
- ,ig_glp_
- ,mce_option2_for_7702
- ,mce_monthly
- )
+ DEndt[Opt1Int4Pct] = CommFns[Opt1Int4Pct].aDomega();
+
+ CommFns[Opt2Int4Pct] = ULCommFns
+ (Qc
+ ,ic_glp_
+ ,ig_glp_
+ ,mce_option2_for_7702
+ ,mce_monthly
);
- DEndt[Opt2Int4Pct] = CommFns[Opt2Int4Pct]->aDomega();
+ DEndt[Opt2Int4Pct] = CommFns[Opt2Int4Pct].aDomega();
// Commutation functions using min i = igsp(): always option 1
- CommFns[Opt1Int6Pct].reset
- (::new ULCommFns
- (Qc
- ,ic_gsp_
- ,ig_gsp_
- ,mce_option1_for_7702
- ,mce_monthly
- )
+ CommFns[Opt1Int6Pct] = ULCommFns
+ (Qc
+ ,ic_gsp_
+ ,ig_gsp_
+ ,mce_option1_for_7702
+ ,mce_monthly
);
- DEndt[Opt1Int6Pct] = CommFns[Opt1Int6Pct]->aDomega();
+ DEndt[Opt1Int6Pct] = CommFns[Opt1Int6Pct].aDomega();
}
/// Set GPT and CVAT corridor factors respecting IssueAge.
@@ -459,8 +440,8 @@ void Irc7702::InitCorridor()
CvatCorridor.resize(Length);
CvatCorridor +=
- CommFns[Opt1Int4Pct]->aD()
- / (CommFns[Opt1Int4Pct]->kM() + DEndt[Opt1Int4Pct])
+ CommFns[Opt1Int4Pct].aD()
+ / (CommFns[Opt1Int4Pct].kM() + DEndt[Opt1Int4Pct])
;
GptCorridor.assign
@@ -490,7 +471,7 @@ void Irc7702::InitPvVectors(EIOBasis const& a_EIOBasis)
// survivorship policy, depending on how its account
// value accumulation is specified.
- ULCommFns const& comm_fns = *CommFns[a_EIOBasis];
+ ULCommFns const& comm_fns = CommFns[a_EIOBasis];
// Present value of charges per policy
@@ -796,14 +777,14 @@ double Irc7702::CalculatePremium
void Irc7702::InitSevenPayPrem()
{
// 7PP = MO / (N0-N7) (limit 7 to maturity year)
- double denom = CFFourPctMin->N()[j];
+ double denom = CFFourPctMin.N()[j];
if((7 + j) < lmi::ssize(q))
{
- denom -= CFFourPctMin->N()[7 + j];
+ denom -= CFFourPctMin.N()[7 + j];
}
LMI_ASSERT(0.0 != denom);
mep_rate[j] =
- ( CFFourPctMin->M()[j]
+ ( CFFourPctMin.M()[j]
/ denom
);
}
diff --git a/ihs_irc7702.hpp b/ihs_irc7702.hpp
index ea866bf..8103ca4 100644
--- a/ihs_irc7702.hpp
+++ b/ihs_irc7702.hpp
@@ -24,14 +24,12 @@
#include "config.hpp"
+#include "commutation_functions.hpp"
#include "mc_enum_type_enums.hpp"
#include "round_to.hpp"
-#include <memory> // unique_ptr
#include <vector>
-class ULCommFns;
-
// Specified amount (specamt) is carefully distinguished from benefit
// amount (bftamt). The former is directly chosen by the owner, and
// typically determines the target premium and underwriting charge.
@@ -89,7 +87,6 @@ class Irc7702 final
,double a_InforceCumPremsPaid
// TODO ?? TAXATION !! Perhaps other arguments are needed for inforce.
);
- ~Irc7702();
void Initialize7702
(double a_BftAmt
@@ -139,9 +136,6 @@ class Irc7702 final
double premiums_paid() const;
private:
- Irc7702(Irc7702 const&) = delete;
- Irc7702& operator=(Irc7702 const&) = delete;
-
// Interest and DB Option basis
enum EIOBasis
{Opt1Int4Pct
@@ -224,20 +218,8 @@ class Irc7702 final
double CumPmts; // Cumulative payments
// Commutation functions
-// TODO ?? Apparently the original reason for using smart pointers
-// was to minimize stack usage in a 16-bit environment; clearly that
-// doesn't matter anymore. TAXATION !! Don't do that then.
-//
// TODO ?? TAXATION !! Consider using std::vector instead of array members.
- std::unique_ptr<ULCommFns> CommFns [NumIOBases];
- // After the Init- functions have executed, we can delete the
- // rather sizeable ULCommFns objects, as long as we keep the
- // endowment-year value of D for each basis. TAXATION !! But
- // not if they're created on the stack. And the meaning of
- // "sizeable" has changed since that comment was written; the
- // object contains nine vectors of double, each of potential
- // length 100, and 9 * 8 * 100 = 7200 bytes is negligible in
- // the twenty-first century.
+ ULCommFns CommFns [NumIOBases];
double DEndt [NumIOBases];
// GPT corridor factors for attained ages [IssueAge, 100]
- [lmi-commits] [lmi] master updated (dd6ee0a -> 8aa09b9), Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 40218dc 03/14: Factor out commutation-function speed tests, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master b8f43e0 06/14: Transpose several unit-test functions, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master e6ed669 01/14: Test guideline premium calculations with more complications, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master b1eecea 02/14: Stabilize unit-test timing, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 28cabc2 04/14: Prefer lambdas to std::bind(), Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 61a04eb 08/14: Make commutation functions default constructible, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master df25463 12/14: Avoid operator new, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master b657767 13/14: Remove conditionals that serve no further purpose, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 23fe71f 11/14: Do away with an undesirable smart pointer [290],
Greg Chicares <=
- [lmi-commits] [lmi] master 485e19b 07/14: Favor the rule of zero, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 762056e 05/14: Prefer PETE's operator<<=() to assign(), Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master ed251fc 09/14: Test implicit special member functions, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master c2087ae 10/14: Update a comment, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 8aa09b9 14/14: Expunge some pointless defect markers [287], Greg Chicares, 2021/04/05