From b68d79407e70899cad6aaf1a57105bae1ef5497d Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Tue, 13 Jun 2017 12:33:03 +0200 Subject: [PATCH] Takes fn by forwarding ref. in for_each_pair, resolves #4148 --- include/util/for_each_pair.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/util/for_each_pair.hpp b/include/util/for_each_pair.hpp index d051e6539..bd6c4dd39 100644 --- a/include/util/for_each_pair.hpp +++ b/include/util/for_each_pair.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace osrm { @@ -12,11 +13,11 @@ namespace util // TODO: check why this is not an option here: // std::adjacent_find(begin, end, [=](const auto& l, const auto& r){ return function(), false; }); template -Function for_each_pair(ForwardIterator begin, ForwardIterator end, Function function) +void for_each_pair(ForwardIterator begin, ForwardIterator end, Function &&function) { if (begin == end) { - return function; + return; } auto next = begin; @@ -24,19 +25,18 @@ Function for_each_pair(ForwardIterator begin, ForwardIterator end, Function func while (next != end) { - function(*begin, *next); + std::forward(function)(*begin, *next); begin = std::next(begin); next = std::next(next); } - return function; } template -Function for_each_pair(ContainerT &container, Function function) +void for_each_pair(ContainerT &container, Function &&function) { using std::begin; using std::end; - return for_each_pair(begin(container), end(container), function); + for_each_pair(begin(container), end(container), std::forward(function)); } } // namespace util