From ba8520d3435c75c2568c05f1333966a4c1a4d69b Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 19 Feb 2020 21:48:29 +0100 Subject: Fix invalid reference bug --- grammer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'grammer.cpp') diff --git a/grammer.cpp b/grammer.cpp index 9df4703..a54b65d 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -374,7 +374,7 @@ std::map Compiler::traverse(const std::string& lower, std::deque> todo{{lower, ""}}; // node, child while (!todo.empty()) { - auto& [current_node, current_child] = todo.front(); + auto [current_node, current_child] = todo.front(); std::string& current_node2{current_node}; // workaround for lambda capture below (clang 8) todo.pop_front(); @@ -387,11 +387,13 @@ std::map Compiler::traverse(const std::string& lower, visited[current_node] = current_child; - std::for_each(parents.begin(), parents.end(), [&](const auto&x) {todo.emplace_back(x, current_node2);}); + std::for_each(parents.begin(), parents.end(), [&](const auto&x) { + todo.push_back({x, current_node2}); + }); } } } - + return visited; } @@ -413,8 +415,9 @@ std::vector Compiler::GetPath(std::string upper, std::string lower) result.push_back(current); current = child; - } else + } else { return {}; + } } return result; } -- cgit v1.2.3