How do I iterate equal values with the standard library?
This is basically Range v3’s group_by: group_by(v, std::equal_to{}). It doesn’t exist in the C++17 standard library, but we can write our own rough equivalent: template <typename FwdIter, typename BinaryPred, typename ForEach> void for_each_equal_range(FwdIter first, FwdIter last, BinaryPred is_equal, ForEach f) { while (first != last) { auto next_unequal = std::find_if_not(std::next(first), last, [&] (auto const& element) … Read more