Re: Free STL compatible C++ tree container
Luca Risolia <luca.risolia@studio.unibo.it> wrote:
The OP proposed his tree data structure as a STL- *compatible*
container. Standard containers do NOT require and use operator==() to
compare elements.
Can you tell me which one of the standard containers uses operator<() for
comparing for equality only, but not for ordering the elements (because
it's an unordered container)?
There aren't any.
The idea is that ordered containers (namely std::set, std::map and their
multi-variants) already require operator<() in order to function at all
because, by definition, they must be able to sort the elements. And since
operator<() can also be used for equality comparison, they use it so as
to not increase the demands for the elements. Also algorithms that require
both operator<() and comparing for equality do not require operator==()
because the latter is not needed when the former is already a requirement.
However, standard algorithms that do *not* require operator<() but *do*
require comparing for equality use operator==(). It would make no sense
for them to do otherwise. It would be nonsensical for eg. std::find() to
require operator<() when it does not work on sorted ranges. It only
requires equality comparisons, and hence operator==().
You are confusing the ideology that a container should require as little
as possible from its elements. The ordered containers and algorithms that
operate on ordered ranges only require operator<() because they need it
anyways to operate properly, and requiring operator==() in addition to
that is superfluous. However, algorithms that require only equality
comparison require operator==() and *not* operator<(), because the former
is much more common and simpler.
Requiring operator<() for equality comparison only, in an unordered data
container, is nonsensical.