Why is operator!= removed in C++20 for many standard library types?

In C++20 the way that the relational operators work was changed, notably with the introduction of the spaceship <=> operator. In particular, If you only provide operator==, then a != b is rewritten to !(a == b). From [over.match.oper]/3.4: The rewritten candidate set is determined as follows: For the relational ([expr.rel]) operators, the rewritten candidates … Read more

operator< comparing multiple fields

I’d like to do it all by myself.. You should only compare the values of Obj::field2 if the values of Obj::field1 are equal. The easy-to-understand way: /* This will meet the requirements of Strict-Weak-Ordering */ if (a.field1 != b.field1) return a.field1 < b.field1; else return a.field2 < b.field2; The correct (recommended) way: The “correct” way … Read more