diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-08-12 23:17:23 -0400 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 2a61664ceb865f6569b916f2c3f1487af8c5d37f (patch) | |
tree | fe287b4fd0a8e46c95450b12cfcca64ebc151c53 | |
parent | 8c2383b4952fa22d41745d29484462ed6a67112b (diff) | |
download | subsurface-2a61664ceb865f6569b916f2c3f1487af8c5d37f.tar.gz |
Undo: correctly fill dive-list vector
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index 1cd1b4e25..d3ecfb796 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -133,7 +133,7 @@ std::vector<DiveToAdd> DiveListBase::removeDives(std::vector<dive *> &divesToDel std::vector<dive *> DiveListBase::addDives(std::vector<DiveToAdd> &divesToAdd) { std::vector<dive *> res; - res.reserve(divesToAdd.size()); + res.resize(divesToAdd.size()); // At the end of the function, to send the proper dives-added signals, // we the the list of added trips. Create this list now. @@ -144,8 +144,11 @@ std::vector<dive *> DiveListBase::addDives(std::vector<DiveToAdd> &divesToAdd) } // Now, add the dives - for (auto it = divesToAdd.rbegin(); it != divesToAdd.rend(); ++it) - res.push_back(addDive(*it)); + // Note: the idiomatic STL-way would be std::transform, but let's use a loop since + // that is closer to classical C-style. + auto it2 = res.rbegin(); + for (auto it = divesToAdd.rbegin(); it != divesToAdd.rend(); ++it, ++it2) + *it2 = addDive(*it); divesToAdd.clear(); // We send one dives-deleted signal per trip (see comments in DiveListNotifier.h). |