26template<
class Vec,
class LogF> Vec
merge_ranges(
const Vec& old_ranges, LogF&& log) {
28 for (
auto it = old_ranges.begin(); it != old_ranges.end(); ++it) {
29 auto current_range = *it;
30 log(
"old range: {}-{}", current_range.first, current_range.second);
31 for (
auto inner = it + 1; inner != old_ranges.end(); ++inner)
32 if (
auto merged =
merge_ranges(current_range, *inner)) current_range = *merged;
34 std::vector<typename Vec::iterator> de_duplicate;
35 for (
auto inner = new_ranges.begin(); inner != new_ranges.end(); ++inner) {
37 current_range = *merged;
38 de_duplicate.push_back(inner);
41 for (
auto dedup : de_duplicate) {
42 log(
"dedup {}-{}", current_range.first, current_range.second);
43 new_ranges.erase(dedup);
45 log(
"new range: {}-{}", current_range.first, current_range.second);
46 new_ranges.push_back(std::move(current_range));