[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 4baec67 2/4: Prefer unique_ptr to shared_ptr
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 4baec67 2/4: Prefer unique_ptr to shared_ptr where appropriate |
Date: |
Sat, 6 Feb 2021 09:00:15 -0500 (EST) |
branch: master
commit 4baec671e0900eec58931fc69098a52c9048c1f5
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Prefer unique_ptr to shared_ptr where appropriate
This is the important change:
* basic_values.hpp: s/shared_ptr/unique_ptr/ for several members.
...which is a little simpler than it would have been if make_shared had
been used: a minor point that seems not to come up in discussions of the
pros and cons of make_shared.
* group_values.cpp: Provide dtors needed to compile and link. They're
not immediately obvious, but the compiler and linker identify their
requirements. The one-time cost of adding these headers amortizes to
nothing. Recompiling this TU whenever any header changes does entail a
modest extra cost.
These changes are the tail that shall not wag the dog:
* antediluvian_stubs.cpp: Provide dtors needed to compile and link.
* basicvalues.cpp: Likewise.
Nobody cares much about the antediluvian branch. It exists only because
it includes some ideas that should be ported to lmi.
---
antediluvian_stubs.cpp | 4 ++++
basic_values.hpp | 18 +++++++++---------
basicvalues.cpp | 2 ++
group_values.cpp | 10 ++++++++++
4 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/antediluvian_stubs.cpp b/antediluvian_stubs.cpp
index 4ef3def..4bc260e 100644
--- a/antediluvian_stubs.cpp
+++ b/antediluvian_stubs.cpp
@@ -21,8 +21,10 @@
#include "pchfile.hpp"
+#include "commutation_functions.hpp"
#include "fund_data.hpp"
#include "gpt_server.hpp"
+#include "ihs_irc7702.hpp"
#include "lingo.hpp"
#include "lmi.hpp" // is_antediluvian_fork()
#include "mec_server.hpp"
@@ -67,6 +69,8 @@ int FundData::GetNumberOfFunds() const
return 0;
}
+Irc7702::~Irc7702() = default;
+
gpt_server::gpt_server(mcenum_emission)
{}
diff --git a/basic_values.hpp b/basic_values.hpp
index e6771a4..04b178d 100644
--- a/basic_values.hpp
+++ b/basic_values.hpp
@@ -35,7 +35,7 @@
#include "so_attributes.hpp"
#include "yare_input.hpp"
-#include <memory> // shared_ptr
+#include <memory> // shared_ptr, unique_ptr
#include <string>
#include <utility> // pair
#include <vector>
@@ -126,14 +126,14 @@ class LMI_SO BasicValues
std::shared_ptr<rounding_rules const> RoundingRules_;
std::shared_ptr<stratified_charges const> StratifiedCharges_;
- std::shared_ptr<MortalityRates> MortalityRates_;
- std::shared_ptr<InterestRates> InterestRates_;
- std::shared_ptr<death_benefits> DeathBfts_;
- std::shared_ptr<modal_outlay> Outlay_;
- std::shared_ptr<premium_tax> PremiumTax_;
- std::shared_ptr<Loads> Loads_;
- std::shared_ptr<Irc7702> Irc7702_;
- std::shared_ptr<Irc7702A> Irc7702A_;
+ std::unique_ptr<MortalityRates> MortalityRates_;
+ std::unique_ptr<InterestRates> InterestRates_;
+ std::unique_ptr<death_benefits> DeathBfts_;
+ std::unique_ptr<modal_outlay> Outlay_;
+ std::unique_ptr<premium_tax> PremiumTax_;
+ std::unique_ptr<Loads> Loads_;
+ std::unique_ptr<Irc7702> Irc7702_;
+ std::unique_ptr<Irc7702A> Irc7702A_;
product_data const& product () const {return *product_;}
product_database const& database() const {return database_;}
diff --git a/basicvalues.cpp b/basicvalues.cpp
index 659277a..584fb85 100644
--- a/basicvalues.cpp
+++ b/basicvalues.cpp
@@ -26,6 +26,8 @@
#include "alert.hpp"
#include "assert_lmi.hpp"
#include "death_benefits.hpp"
+#include "ihs_irc7702.hpp" // dtor only, for (unused) unique_ptr
+#include "ihs_irc7702a.hpp" // dtor only, for (unused) unique_ptr
#include "input.hpp"
#include "interest_rates.hpp"
#include "loads.hpp"
diff --git a/group_values.cpp b/group_values.cpp
index f779fa5..78cbe74 100644
--- a/group_values.cpp
+++ b/group_values.cpp
@@ -42,6 +42,16 @@
#include "timer.hpp"
#include "value_cast.hpp"
+// Headers required only for dtors of objects held by std::unique_ptr.
+#include "death_benefits.hpp"
+#include "ihs_irc7702.hpp"
+#include "ihs_irc7702a.hpp"
+#include "interest_rates.hpp"
+#include "loads.hpp"
+#include "mortality_rates.hpp"
+#include "outlay.hpp"
+#include "premium_tax.hpp"
+
#include <algorithm> // max()
#include <iterator> // back_inserter()
#include <string>