As far as I know, map keeps the data inside sorted and uses the "<" operator for this purpose.
Sort of, but not directly. std::map<Key, T, Compare, Allocator>
uses Compare
for that purpose. Compare
defaults to std::less<Key>
, which in turn typically defaults to using the <
operator. However, even in the standard library implementation, there are cases where std::less<Key>
behaves differently from <
.
What happens if I don't overload "<" operator for that class?
That depends. You can specify a different class as the Compare
template argument which avoids using std::less
. You can add a specialisation of std::less
which avoids using <
. But if you don't do either, you'll typically get error messages about <
not being defined.