top | item 44548347 (no title) Gupie | 7 months ago Why can't you use this for the comparison operator: bool operator<(const interval& x, const interval& y) { if x.min < y.min return true; if x.min > y.min return false; return x_max < y.max; } discuss order hn newest mgaunard|7 months ago better implemented as tie(x.min, x.max) < tie(y.min, y.max) gsliepen|7 months ago Or since C++20, just default operator<=>: https://en.cppreference.com/w/cpp/language/default_compariso... Sharlin|7 months ago That’s fine if you just need any well-defined SWO, but I presume the author needs this specific ordering for some algorithmic reason. Still, it’s pretty ugly for a comparator to be throwing.
mgaunard|7 months ago better implemented as tie(x.min, x.max) < tie(y.min, y.max) gsliepen|7 months ago Or since C++20, just default operator<=>: https://en.cppreference.com/w/cpp/language/default_compariso...
gsliepen|7 months ago Or since C++20, just default operator<=>: https://en.cppreference.com/w/cpp/language/default_compariso...
Sharlin|7 months ago That’s fine if you just need any well-defined SWO, but I presume the author needs this specific ordering for some algorithmic reason. Still, it’s pretty ugly for a comparator to be throwing.
mgaunard|7 months ago
gsliepen|7 months ago
Sharlin|7 months ago