Associative containers STL
You mean: C ++ standard sorted associative containers.
I would expect STL containers to just take an extra default parameter for equality.
What would it be? In your tutorial, the red-black tree algorithm instead
if (x < y) // ... else if (y < x) // ... else // equality
you will have
if (x == y) // equality else if (x < y) // ... else // y < x
so two more comparisons in the worst case.
Responding to comments on this answer: the presence of only an operator with fewer operators makes containers more convenient to use, since there is no need to maintain consistency between smaller and equal. Imagine you have a program that stores floating point numbers. One day, someone decides to replace the function of bitwise equality float_equals , which was just used by some container, as well as their code, by approximate comparison. If this person does not update the float_less function because their code does not use this function, then your container code mysteriously breaks.
(Oh, and in the above code example, a short circuit is applied, as always.)
Fred foo
source share