std::unordered_map (3) - Linux Manuals
std::unordered_map: std::unordered_map
NAME
std::unordered_map - std::unordered_map
Synopsis
Defined in header <unordered_map>
template<
class Key,
class T,
class Hash = std::hash<Key>, (1) (since C++11)
class KeyEqual = std::equal_to<Key>,
class Allocator = std::allocator< std::pair<const Key, T> >
> class unordered_map;
namespace pmr {
template <class Key,
class T,
class Hash = std::hash<Key>, (2) (since C++17)
class Pred = std::equal_to<Key>>
using unordered_map = std::unordered_map<Key, T, Hash, Pred,
std::pmr::polymorphic_allocator<std::pair<const Key,T>>>;
}
Unordered map is an associative container that contains key-value pairs with unique keys. Search, insertion, and removal of elements have average constant-time complexity.
Internally, the elements are not sorted in any particular order, but organized into buckets. Which bucket an element is placed into depends entirely on the hash of its key. This allows fast access to individual elements, since once the hash is computed, it refers to the exact bucket the element is placed into.
std::unordered_map meets the requirements of Container, AllocatorAwareContainer, UnorderedAssociativeContainer.
Iterator invalidation
Operations Invalidated
All read only operations, swap, std::swap Never
clear, rehash, reserve, operator= Always
insert, emplace, emplace_hint, operator[] Only if causes rehash
erase Only to the element erased
Notes
* The swap functions do not invalidate any of the iterators inside the container, but they do invalidate the iterator marking the end of the swap region.
* References and pointers to either key or data stored in the container are only invalidated by erasing that element, even when the corresponding iterator is invalidated.
Member types
Member type Definition
key_type Key
mapped_type T
value_type std::pair<const Key, T>
size_type Unsigned integer type (usually std::size_t)
difference_type Signed integer type (usually std::ptrdiff_t)
hasher Hash
key_equal KeyEqual (until C++20)
allocator_type Allocator
reference value_type&
const_reference const value_type&
pointer std::allocator_traits<Allocator>::pointer
const_pointer std::allocator_traits<Allocator>::const_pointer
iterator LegacyForwardIterator
const_iterator Constant LegacyForwardIterator
local_iterator reference types are the same as iterator. This iterator
const_local_iterator reference types are the same as const_iterator. This iterator
node_type(since C++17) a specialization of node_handle representing a container node