Could anybody explain me what is the difference between overload ==
and <
?
For example, if I use a map:
map
The requirements that the C++ standard places on std::map mean that it is implemented as a self-balancing binary search tree. This means that some kind of ordering comparison between elements must be available. In the case of std::map
, the requirement is a strict weak ordering, and the default is a less-than comparison. This is all that is required to arrange elements in a binary tree, and the equality condition is met when one element (call it A) is not less than another one (call it B), and the converse is also true, i.e. B is not less than A. An equality comparison could have been used, but this would open some scope for inconsistency. If you look at hash tables, such as std::unordered_map, you will find that an equality comparison is indeed required, although this is only to resolve collisions.