-
Notifications
You must be signed in to change notification settings - Fork 1
Description
This is a feature request.
I recognize that NumericRangeComparator<T>::operator() throws a runtime error because it only produces valid results for disjoint ranges. However, the result of this behavior is that this comparator can't produce a total ordering of an arbitrary set of NumericRange objects. This comparator doesn't live up to the guarantees that most other comparators provide, and this could upset users who wanted to sort (or store in a std::map) ranges that happen to overlap. I would argue that this comparator is not as useful as some possible alternatives, and I think you should implement all three of these:
NumericRangeStartComparator: Compare two ranges by their minima, or starting values. Ending values serve as a tiebreaker.NumericRangeEndComparator: Compare two ranges by their maxima, or ending values. Starting values serve as a tiebreaker.NumericRangeCenterComparator: Compare two ranges by their center values. The length of the range (end minus start) serves as a tiebreaker.
I suspect that each of these will be a bit cleaner to implement than the original NumericRangeComparator.
All of these give total orderings of arbitrary sets of NumericRange objects, and produce deterministic results. (Don't forget the tiebreakers, because they provide this determinism).