When I make a std::map
, what C++ expects from me is that my_data_type
has its own operator<
.
The reason why a comparison operator is needed is the way map is implemented: as a binary search tree, which allows you to look up, insert and delete elements in O(log n)
. In order to build this tree, a strict weak order must be defined for the set of keys. That's why only one operator definition is needed.