osrm-backend/include/util/for_each_pair.hpp

43 lines
990 B
C++
Raw Normal View History

#ifndef FOR_EACH_PAIR_HPP
#define FOR_EACH_PAIR_HPP
#include <iterator>
2016-05-27 15:05:04 -04:00
#include <numeric>
#include <utility>
namespace osrm::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>
void for_each_pair(ForwardIterator begin, ForwardIterator end, Function &&function)
{
if (begin == end)
{
return;
}
auto next = begin;
next = std::next(next);
while (next != end)
{
std::forward<Function>(function)(*begin, *next);
begin = std::next(begin);
next = std::next(next);
}
}
template <class ContainerT, typename Function>
void for_each_pair(ContainerT &container, Function &&function)
{
using std::begin;
using std::end;
for_each_pair(begin(container), end(container), std::forward<Function>(function));
}
2022-12-20 12:00:11 -05:00
} // namespace osrm::util
#endif /* FOR_EACH_PAIR_HPP */