What requirements must a class meet to be used as a key in a std::map versus a std::unordered_map?
Last updated
std::map(balanced BST, O(log n)) needs a strict weak ordering, by defaultoperator<viastd::less. Keys are equal when neither is less than the other.std::unordered_map(hash table, average O(1)) needs a hash functor (std::hashspecialization or custom hasher) plus equality (operator==).In both, the key must stay effectively immutable while stored, since changing the ordered/hashed parts corrupts the container.