Fix iterator invalidation when appending to vector

Reviewers: mtomic, mferencevic

Reviewed By: mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1979
This commit is contained in:
Teon Banek 2019-04-24 16:22:29 +02:00
parent c2bc5fe377
commit 4a3df704b6

View File

@ -63,9 +63,10 @@ std::vector<std::pair<int, int>> GetEdgeList(
for (auto &e : ret) std::swap(e.first, e.second);
break;
case query::EdgeAtom::Direction::BOTH:
std::transform(
ret.begin(), ret.end(), std::back_inserter(ret),
[](const auto &e) { return std::make_pair(e.second, e.first); });
auto ret_copy = ret;
for (const auto &e : ret_copy) {
ret.emplace_back(e.second, e.first);
}
break;
}
return ret;