Namespaces
Variants

Standard library header <unordered_map> (C++11)

From cppreference.net
Standard library headers

此头文件属于 容器 库。

目录

包含文件

(C++20)
三路比较运算符 支持
std::initializer_list 类模板

键值对集合,按键哈希,键唯一
(类模板)
键值对集合,按键哈希
(类模板)

函数

(C++11) (C++11) (C++20 中移除)
比较 unordered_map 中的值
(函数模板)
特化 std::swap 算法
(函数模板)
擦除满足特定条件的所有元素
(函数模板)
(C++11) (C++11) (C++20 中移除)
比较 unordered_multimap 中的值
(函数模板)
特化 std::swap 算法
(函数模板)
擦除满足特定条件的所有元素
(函数模板)
范围访问
(C++11) (C++14)
返回指向容器或数组起始的迭代器
(函数模板)
(C++11) (C++14)
返回指向容器或数组末尾的迭代器
(函数模板)
返回指向容器或数组起始的反向迭代器
(函数模板)
(C++14)
返回容器或数组的逆向末尾迭代器
(函数模板)
(C++17) (C++20)
返回容器或数组的大小
(函数模板)

概要

#include <compare>
#include <initializer_list>
namespace std {
  // 类模板 unordered_map
  template<class Key,
           class T,
           class Hash  = hash<Key>,
           class Pred  = equal_to<Key>,
           class Alloc = allocator<pair<const Key, T>>>
  class unordered_map;
  // 类模板 unordered_multimap
  template<class Key,
           class T,
           class Hash  = hash<Key>,
           class Pred  = equal_to<Key>,
           class Alloc = allocator<pair<const Key, T>>>
  class unordered_multimap;
  template<class Key, class T, class Hash, class Pred, class Alloc>
  bool operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& a,
                  const unordered_map<Key, T, Hash, Pred, Alloc>& b);
  template<class Key, class T, class Hash, class Pred, class Alloc>
  bool operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& a,
                  const unordered_multimap<Key, T, Hash, Pred, Alloc>& b);
  template<class Key, class T, class Hash, class Pred, class Alloc>
  void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
            unordered_map<Key, T, Hash, Pred, Alloc>& y) noexcept(noexcept(x.swap(y)));
  template<class Key, class T, class Hash, class Pred, class Alloc>
  void swap(
    unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
    unordered_multimap<Key, T, Hash, Pred, Alloc>& y) noexcept(noexcept(x.swap(y)));
  // unordered_map 的擦除操作
  template<class K, class T, class H, class P, class A, class Predicate>
  typename unordered_map<K, T, H, P, A>::size_type erase_if(
    unordered_map<K, T, H, P, A>& c,
    Predicate pred);
  // unordered_multimap 的擦除操作
  template<class K, class T, class H, class P, class A, class Predicate>
  typename unordered_multimap<K, T, H, P, A>::size_type erase_if(
    unordered_multimap<K, T, H, P, A>& c,
    Predicate pred);
  namespace pmr {
    template<class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>>
    using unordered_map =
      std::unordered_map<Key, T, Hash, Pred, polymorphic_allocator<pair<const Key, T>>>;
    template<class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>>
    using unordered_multimap = std::
      unordered_multimap<Key, T, Hash, Pred, polymorphic_allocator<pair<const Key, T>>>;
  }
}

类模板 std::unordered_map

namespace std {
  template<class Key,
           class T,
           class Hash      = hash<Key>,
           class Pred      = equal_to<Key>,
           class Allocator = allocator<pair<const Key, T>>>
  class unordered_map
  {
  public:
    // 类型
    using key_type             = Key;
    using mapped_type          = T;
    using value_type           = pair<const Key, T>;
    using hasher               = Hash;
    using key_equal            = Pred;
    using allocator_type       = Allocator;
    using pointer              = typename allocator_traits<Allocator>::pointer;
    using const_pointer        = typename allocator_traits<Allocator>::const_pointer;
    using reference            = value_type&;
    using const_reference      = const value_type&;
    using size_type            = /* 实现定义 */;
    using difference_type      = /* 实现定义 */;
    using iterator             = /* 实现定义 */;
    using const_iterator       = /* 实现定义 */;
    using local_iterator       = /* 实现定义 */;
    using const_local_iterator = /* 实现定义 */;
    using node_type            = /* 未指定 */;
    using insert_return_type   = /*插入返回类型*/<iterator, node_type>;
    // 构造/复制/销毁
    unordered_map();
    explicit unordered_map(size_type n,
                           const hasher& hf        = hasher(),
                           const key_equal& eql    = key_equal(),
                           const allocator_type& a = allocator_type());
    template<class InputIter>
    unordered_map(InputIter f,
                  InputIter l,
                  size_type n             = /* 参见描述 */,
                  const hasher& hf        = hasher(),
                  const key_equal& eql    = key_equal(),
                  const allocator_type& a = allocator_type());
    template<container-compatible-range<value_type> R>
    unordered_map(from_range_t,
                  R&& rg,
                  size_type n             = /* 参见描述 */,
                  const hasher& hf        = hasher(),
                  const key_equal& eql    = key_equal(),
                  const allocator_type& a = allocator_type());
    unordered_map(const unordered_map&);
    unordered_map(unordered_map&&);
    explicit unordered_map(const Allocator&);
    unordered_map(const unordered_map&, const type_identity_t<Allocator>&);
    unordered_map(unordered_map&&, const type_identity_t<Allocator>&);
    unordered_map(initializer_list<value_type> il,
                  size_type n             = /* 参见描述 */,
                  const hasher& hf        = hasher(),
                  const key_equal& eql    = key_equal(),
                  const allocator_type& a = allocator_type());
    unordered_map(size_type n, const allocator_type& a)
      : unordered_map(n, hasher(), key_equal(), a)
    {
    }
    unordered_map(size_type n, const hasher& hf, const allocator_type& a)
      : unordered_map(n, hf, key_equal(), a)
    {
    }
    template<class InputIter>
    unordered_map(InputIter f, InputIter l, size_type n, const allocator_type& a)
      : unordered_map(f, l, n, hasher(), key_equal(), a)
    {
    }
    template<class InputIter>
    unordered_map(InputIter f,
                  InputIter l,
                  size_type n,
                  const hasher& hf,
                  const allocator_type& a)
      : unordered_map(f, l, n, hf, key_equal(), a)
    {
    }
    template<container-compatible-range<value_type> R>
    unordered_map(from_range_t, R&& rg, size_type n, const allocator_type& a)
      : unordered_map(from_range, std::forward<R>(rg), n, hasher(), key_equal(), a)
    {
    }
    template<container-compatible-range<value_type> R>
    unordered_map(from_range_t,
                  R&& rg,
                  size_type n,
                  const hasher& hf,
                  const allocator_type& a)
      <span class="sy4

类模板 std::unordered_multimap

namespace std {
  template<class Key,
           class T,
           class Hash      = hash<Key>,
           class Pred      = equal_to<Key>,
           class Allocator = allocator<pair<const Key, T>>>
  class unordered_multimap
  {
  public:
    // 类型定义
    using key_type             = Key;
    using mapped_type          = T;
    using value_type           = pair<const Key, T>;
    using hasher               = Hash;
    using key_equal            = Pred;
    using allocator_type       = Allocator;
    using pointer              = typename allocator_traits<Allocator>::pointer;
    using const_pointer        = typename allocator_traits<Allocator>::const_pointer;
    using reference            = value_type&;
    using const_reference      = const value_type&;
    using size_type            = /* 由实现定义 */;
    using difference_type      = /* 由实现定义 */;
    using iterator             = /* 由实现定义 */;
    using const_iterator       = /* 由实现定义 */;
    using local_iterator       = /* 由实现定义 */;
    using const_local_iterator = /* 由实现定义 */;
    using node_type            = /* 未指定 */;
    // 构造/复制/销毁
    unordered_multimap();
    explicit unordered_multimap(size_type n,
                                const hasher& hf        = hasher(),
                                const key_equal& eql    = key_equal(),
                                const allocator_type& a = allocator_type());
    template<class InputIter>
    unordered_multimap(InputIter f,
                       InputIter l,
                       size_type n             = /* 见描述 */,
                       const hasher& hf        = hasher(),
                       const key_equal& eql    = key_equal(),
                       const allocator_type& a = allocator_type());
    template<container-compatible-range<value_type> R>
    unordered_multimap(from_range_t,
                       R&& rg,
                       size_type n             = /* 见描述 */,
                       const hasher& hf        = hasher(),
                       const key_equal& eql    = key_equal(),
                       const allocator_type& a = allocator_type());
    unordered_multimap(const unordered_multimap&);
    unordered_multimap(unordered_multimap&&);
    explicit unordered_multimap(const Allocator&);
    unordered_multimap(const unordered_multimap&, const type_identity_t<Allocator>&);
    unordered_multimap(unordered_multimap&&, const type_identity_t<Allocator>&);
    unordered_multimap(initializer_list<value_type> il,
                       size_type n             = /* 见描述 */,
                       const hasher& hf        = hasher(),
                       const key_equal& eql    = key_equal(),
                       const allocator_type& a = allocator_type());
    unordered_multimap(size_type n, const allocator_type& a)
      : unordered_multimap(n, hasher(), key_equal(), a)
    {
    }
    unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
      : unordered_multimap(n, hf, key_equal(), a)
    {
    }
    template<class InputIter>
    unordered_multimap(InputIter f, InputIter l, size_type n, const allocator_type& a)
      : unordered_multimap(f, l, n, hasher(), key_equal(), a)
    {
    }
    template<class InputIter>
    unordered_multimap(InputIter f,
                       InputIter l,
                       size_type n,
                       const hasher& hf,
                       const allocator_type& a)
      : unordered_multimap(f, l, n, hf, key_equal(), a)
    {
    }
    template<container-compatible-range<value_type> R>
    unordered_multimap(from_range_t, R&& rg, size_type n, const allocator_type& a)
      : unordered_multimap(from_range, std::forward<R>(rg), n, hasher(), key_equal(), a)
    {
    }
    template<container-compatible-range<value_type> R>
    unordered_multimap(from_range_t,
                       R&& rg,
                       size_type n,
                       const hasher& hf,
                       const allocator_type& a)
      : unordered_multimap(from