Skip to content

Commit b68d794

Browse files
daniel-j-hPatrick Niklaus
authored andcommitted
Takes fn by forwarding ref. in for_each_pair, resolves #4148
1 parent 27ed69b commit b68d794

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

include/util/for_each_pair.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <iterator>
55
#include <numeric>
6+
#include <utility>
67

78
namespace osrm
89
{
@@ -12,31 +13,30 @@ namespace util
1213
// TODO: check why this is not an option here:
1314
// std::adjacent_find(begin, end, [=](const auto& l, const auto& r){ return function(), false; });
1415
template <typename ForwardIterator, typename Function>
15-
Function for_each_pair(ForwardIterator begin, ForwardIterator end, Function function)
16+
void for_each_pair(ForwardIterator begin, ForwardIterator end, Function &&function)
1617
{
1718
if (begin == end)
1819
{
19-
return function;
20+
return;
2021
}
2122

2223
auto next = begin;
2324
next = std::next(next);
2425

2526
while (next != end)
2627
{
27-
function(*begin, *next);
28+
std::forward<Function>(function)(*begin, *next);
2829
begin = std::next(begin);
2930
next = std::next(next);
3031
}
31-
return function;
3232
}
3333

3434
template <class ContainerT, typename Function>
35-
Function for_each_pair(ContainerT &container, Function function)
35+
void for_each_pair(ContainerT &container, Function &&function)
3636
{
3737
using std::begin;
3838
using std::end;
39-
return for_each_pair(begin(container), end(container), function);
39+
for_each_pair(begin(container), end(container), std::forward<Function>(function));
4040
}
4141

4242
} // namespace util

0 commit comments

Comments
 (0)