[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 86bf250 2/6: Reorder a statement
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 86bf250 2/6: Reorder a statement |
Date: |
Fri, 19 Oct 2018 15:45:06 -0400 (EDT) |
branch: master
commit 86bf2501a1c39fb2b18d4b619acc71daeb9e011a
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Reorder a statement
In this group loop, it's necessary only to follow the same order as
IllusVal::run():
- create an AccountValue object
- set its monthly-trace filename
- perform the same steps as AccountValue::RunAV()
Moving the statement that stores the AccountValue object in a container
has no effect on observable results.
However, the code was not robust:
smart_pointer p(values);
p->do_something();
container.push_back(p);
p->do_something_else();
because it works with std::shared_ptr, but not with std::unique_ptr
after the necessary change:
p->do_something();
- container.push_back(p);
+ container.push_back(std::move(p));
p->do_something_else(); // oops: p has been moved from
The next commit, separated for clarity, further improves robustness.
---
group_values.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/group_values.cpp b/group_values.cpp
index b422971..2e44cff 100644
--- a/group_values.cpp
+++ b/group_values.cpp
@@ -268,14 +268,14 @@ census_run_result run_census_in_parallel::operator()
{ // Begin fenv_guard scope.
fenv_guard fg;
std::shared_ptr<AccountValue> av(new AccountValue(ip));
+ cell_values.push_back(av);
+
std::string const name(cells[j]["InsuredName"].str());
// Indexing: here, j is an index into cells, not cell_values.
av->SetDebugFilename
(serial_file_path(file, name, j, "hastur").string()
);
- cell_values.push_back(av);
-
if(contains(av->yare_input_.Comments, "idiosyncrasyZ"))
{
av->Debugging = true;
- [lmi-commits] [lmi] master updated (4c21bf7 -> 2ba6003), Greg Chicares, 2018/10/19
- [lmi-commits] [lmi] master 8eead43 4/6: Don't write 'new', Greg Chicares, 2018/10/19
- [lmi-commits] [lmi] master 4d87259 3/6: Create and use a proper alias, Greg Chicares, 2018/10/19
- [lmi-commits] [lmi] master d2b8c01 1/6: Improve physical design: unique_ptr member --> out-of-line ~owner(), Greg Chicares, 2018/10/19
- [lmi-commits] [lmi] master bc32401 5/6: Replace std::shared_ptr with std::unique_ptr, Greg Chicares, 2018/10/19
- [lmi-commits] [lmi] master 86bf250 2/6: Reorder a statement,
Greg Chicares <=
- [lmi-commits] [lmi] master 2ba6003 6/6: Dispense with smart pointers, Greg Chicares, 2018/10/19