From 2a61664ceb865f6569b916f2c3f1487af8c5d37f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 12 Aug 2018 23:17:23 -0400 Subject: Undo: correctly fill dive-list vector Signed-off-by: Berthold Stoeger --- desktop-widgets/command_divelist.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'desktop-widgets') 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 DiveListBase::removeDives(std::vector &divesToDel std::vector DiveListBase::addDives(std::vector &divesToAdd) { std::vector 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 DiveListBase::addDives(std::vector &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). -- cgit v1.2.3-70-g09d2