[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master b98ef0c 6/6: Refactor for clarity [392]
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master b98ef0c 6/6: Refactor for clarity [392] |
Date: |
Mon, 13 Mar 2017 09:46:15 -0400 (EDT) |
branch: master
commit b98ef0cad57bd8a2be50652893a28ea21b8b75b8
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Refactor for clarity [392]
See:
http://lists.nongnu.org/archive/html/lmi/2017-03/msg00081.html
---
ledger.cpp | 40 +++++++++++++++++++---------------------
1 file changed, 19 insertions(+), 21 deletions(-)
diff --git a/ledger.cpp b/ledger.cpp
index 1db9e62..047b9e7 100644
--- a/ledger.cpp
+++ b/ledger.cpp
@@ -148,34 +148,32 @@ void Ledger::SetRunBases(int length)
}
}
-//============================================================================
-// TODO ?? This seems to be a bad idea: it zeroes what should already
-// have been zero.
+/// Pick the highest lapse year of any basis (i.e. any LedgerVariant).
+/// Set inforce lives to zero at the end of that year and thereafter.
+/// This is extremely likely to mean the lapse year on the current
+/// basis; but if it's the lapse year on some other basis, we don't
+/// want to truncate values on that other basis, even if it means
+/// that the vector of inforce lives does not correspond to the
+/// current values.
+///
+/// SOMEDAY !! Reconsider whether the values this function sets to
+/// zero should already have been zero.
+
void Ledger::ZeroInforceAfterLapse()
{
ledger_map_t const& l_map_rep = ledger_map_->held();
-
- // Pick the highest lapse year of any basis (i.e. any LedgerVariant).
- // Set inforce lives to zero at the end of that year and thereafter.
- // This is extremely likely to mean the lapse year on the current
- // basis; but if it's the lapse year on some other basis, we don't
- // want to truncate values on that other basis, even if it means
- // that the vector of inforce lives does not correspond to the
- // current values.
- int lapse_year = 0;
+ using T = decltype(ledger_invariant_->InforceLives)::size_type;
+ T original_length = ledger_invariant_->InforceLives.size();
+ T lapse_year = T(0);
for(auto const& i : l_map_rep)
{
- lapse_year = std::max
- (lapse_year
- ,static_cast<int>(i.second.LapseYear)
- );
+ lapse_year = std::max(lapse_year, static_cast<T>(i.second.LapseYear));
}
- std::vector<double>::iterator b = ledger_invariant_->InforceLives.begin();
- std::vector<double>::iterator e = ledger_invariant_->InforceLives.end();
- b += std::min(static_cast<int>(e - b), 1 + lapse_year);
- if(b < e)
+ T unlapsed_length = 1 + lapse_year;
+ if(unlapsed_length < original_length)
{
- std::fill(b, e, 0.0);
+ ledger_invariant_->InforceLives.resize(unlapsed_length);
+ ledger_invariant_->InforceLives.resize(original_length);
}
}
- [lmi-commits] [lmi] master updated (197119c -> b98ef0c), Greg Chicares, 2017/03/13
- [lmi-commits] [lmi] master 859e100 1/6: Move implementation of pure virtual dtor out of header, Greg Chicares, 2017/03/13
- [lmi-commits] [lmi] master 9ef5990 2/6: Disable gcc -Wcast-qual warning for wx in the code, not makefile, Greg Chicares, 2017/03/13
- [lmi-commits] [lmi] master b98ef0c 6/6: Refactor for clarity [392],
Greg Chicares <=
- [lmi-commits] [lmi] master ba65912 5/6: Include the appropriate PCH header, Greg Chicares, 2017/03/13
- [lmi-commits] [lmi] master 351bf57 4/6: Improve documentation, Greg Chicares, 2017/03/13
- [lmi-commits] [lmi] master 25b5804 3/6: Remove the now unnecessary wx/defs.h inclusions, Greg Chicares, 2017/03/13