Takes fn by forwarding ref. in for_each_pair, resolves #4148
This commit is contained in:
parent
27ed69b08f
commit
b68d79407e
@ -3,6 +3,7 @@
|
||||
|
||||
#include <iterator>
|
||||
#include <numeric>
|
||||
#include <utility>
|
||||
|
||||
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 <typename ForwardIterator, typename Function>
|
||||
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>(function)(*begin, *next);
|
||||
begin = std::next(begin);
|
||||
next = std::next(next);
|
||||
}
|
||||
return function;
|
||||
}
|
||||
|
||||
template <class ContainerT, typename Function>
|
||||
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>(function));
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
Loading…
Reference in New Issue
Block a user