Vectors of ranges

struct range {
    int begin;
    int end;
};

x::sorted_range<range> ranges;

ranges.add(range{1, 5});
ranges.add(range{3,10});
ranges.remove(range{4,7});
      

The x::sorted_range template implements a subclass of a std::vector that stores a sorted list of ranges. The template parameter is a class with begin and end members. These values specify a range defined by the begin value and up to but not including the end value.

add() and remove() update the sorted list of ranges, automatically removing overlapping and duplicate ranges. Other methods implement several additional operations on the sorted range.