[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 6acb17a 1/3: Don't write std::iota() by hand
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 6acb17a 1/3: Don't write std::iota() by hand |
Date: |
Tue, 2 Oct 2018 13:45:08 -0400 (EDT) |
branch: master
commit 6acb17ac80c8582e0b56e1191fcb051d4cb981ed
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Don't write std::iota() by hand
See:
https://lists.nongnu.org/archive/html/lmi/2018-10/msg00002.html
(which ought to have referred to this commit instead of f1af0f95).
---
ledger_evaluator.cpp | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/ledger_evaluator.cpp b/ledger_evaluator.cpp
index c169d83..96d7569 100644
--- a/ledger_evaluator.cpp
+++ b/ledger_evaluator.cpp
@@ -49,6 +49,7 @@
#include <algorithm> // transform()
#include <functional> // minus
#include <map>
+#include <numeric> // iota()
#include <unordered_map>
#include <utility> // move(), pair
@@ -706,20 +707,12 @@ ledger_evaluator Ledger::make_evaluator() const
double MaxDuration = ledger_invariant_->EndtAge - ledger_invariant_->Age;
scalars["MaxDuration"] = &MaxDuration;
int max_duration = static_cast<int>(MaxDuration);
-
- std::vector<double> PolicyYear;
- std::vector<double> AttainedAge;
-
- PolicyYear .resize(max_duration);
- AttainedAge.resize(max_duration);
-
int issue_age = static_cast<int>(ledger_invariant_->Age);
- for(int j = 0; j < max_duration; ++j)
- {
- PolicyYear[j] = 1 + j;
- AttainedAge[j] = 1 + j + issue_age;
- }
+ std::vector<double> PolicyYear (max_duration);
+ std::vector<double> AttainedAge(max_duration);
+ std::iota(PolicyYear .begin(), PolicyYear .end(), 1);
+ std::iota(AttainedAge.begin(), AttainedAge.end(), 1 + issue_age);
// TODO ?? An attained-age column is meaningless in a composite. So
// are several others--notably those affected by partial mortaility.
vectors["AttainedAge"] = &AttainedAge;