You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

24 lines
689 B

#pragma once
#include <iterator>
namespace algorithm
{
// comp returns true if lhs is thought to be less than rhs
// f(start, end)
template <typename InputIt, typename Compare, typename F>
void operate_on_set_intervals(InputIt first, InputIt last, Compare comp, F f)
{
if (first == last) return;
for (InputIt prev_iter = first++; first != last; ++first, ++prev_iter) {
if (comp(*prev_iter, *first)) f(*prev_iter, *first);
}
}
// f(start, end)
template <typename InputIt, typename F>
void operate_on_set_intervals(InputIt first, InputIt last, F f)
{
operate_on_set_intervals(first, last, std::less<std::decay_t<decltype(*first)>>{}, f);
}
} // namespace algorithm