Namespaces
Variants

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

From cppreference.net
Standard library headers

此头文件是 容器 库的组成部分。

目录

包含文件

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

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

函数

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

概要

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

类模板 std::unordered_set

namespace std {
  template<class Key,
           class Hash      = hash<Key>,
           class Pred      = equal_to<Key>,
           class Allocator = allocator<Key>>
  class unordered_set
  {
  public:
    // 类型定义
    using key_type             = Key;
    using value_type           = Key;
    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_set();
    explicit unordered_set(size_type n,
                           const hasher& hf        = hasher(),
                           const key_equal& eql    = key_equal(),
                           const allocator_type& a = allocator_type());
    template<class InputIter>
    unordered_set(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_set(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_set(const unordered_set&);
    unordered_set(unordered_set&&);
    explicit unordered_set(const Allocator&);
    unordered_set(const unordered_set&, const type_identity_t<Allocator>&);
    unordered_set(unordered_set&&, const type_identity_t<Allocator>&);
    unordered_set(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_set(size_type n, const allocator_type& a)
      : unordered_set(n, hasher(), key_equal(), a)
    {
    }
    unordered_set(size_type n, const hasher& hf, const allocator_type& a)
      : unordered_set(n, hf, key_equal(), a)
    {
    }
    template<class InputIter>
    unordered_set(InputIter f, InputIter l, size_type n, const allocator_type& a)
      : unordered_set(f, l, n, hasher(), key_equal(), a)
    {
    }
    template<class InputIter>
    unordered_set(InputIter f,
                  InputIter l,
                  size_type n,
                  const hasher& hf,
                  const allocator_type& a)
      : unordered_set(f, l, n, hf, key_equal(), a)
    {
    }
    unordered_set(initializer_list<value_type> il, size_type n, const allocator_type& a)
      : unordered_set(il, n, hasher(), key_equal(), a)
    {
    }
    template<container-compatible-range<value_type> R>
    unordered_set(from_range_t, R&& rg, size_type n, const allocator_type& a)
      : unordered_set(from_range, std::forward<R>(rg), n, hasher(), key_equal(), a)
    {
    }
    template<container-compatible-range<value_type> R>
    unordered_set(from_range_t,
                  R&& rg,
                  size_type

类模板 std::unordered_multiset

namespace std {
  template<class Key,
           class Hash      = hash<Key>,
           class Pred      = equal_to<Key>,
           class Allocator = allocator<Key>>
  class unordered_multiset
  {
  public:
    // 类型定义
    using key_type             = Key;
    using value_type           = Key;
    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_multiset();
    explicit unordered_multiset(size_type n,
                                const hasher& hf        = hasher(),
                                const key_equal& eql    = key_equal(),
                                const allocator_type& a = allocator_type());
    template<class InputIter>
    unordered_multiset(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_multiset(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_multiset(const unordered_multiset&);
    unordered_multiset(unordered_multiset&&);
    explicit unordered_multiset(const Allocator&);
    unordered_multiset(const unordered_multiset&, const type_identity_t<Allocator>&);
    unordered_multiset(unordered_multiset&&, const type_identity_t<Allocator>&);
    unordered_multiset(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_multiset(size_type n, const allocator_type& a)
      : unordered_multiset(n, hasher(), key_equal(), a)
    {
    }
    unordered_multiset(size_type n, const hasher& hf, const allocator_type& a)
      : unordered_multiset(n, hf, key_equal(), a)
    {
    }
    template<class InputIter>
    unordered_multiset(InputIter f, InputIter l, size_type n, const allocator_type& a)
      : unordered_multiset(f, l, n, hasher(), key_equal(), a)
    {
    }
    template<class InputIter>
    unordered_multiset(InputIter f,
                       InputIter l,
                       size_type n,
                       const hasher& hf,
                       const allocator_type& a)
      : unordered_multiset(f, l, n, hf, key_equal(), a)
    {
    }
    template<container-compatible-range<value_type> R>
    unordered_multiset(from_range_t, R&& rg, size_type n, const allocator_type& a)
      : unordered_multiset(from_range, std::forward<R>(rg), n, hasher(), key_equal(), a)
    {
    }
    template<container-compatible-range<value_type> R>
    unordered_multiset(from_range_t,
                       R&& rg,
                       size_type n,
                       const hasher& hf,
                       const allocator_type& a)
      : unordered_multiset(from_range, std::forward<R>(rg), n, hf, key_equal(), a)
    {
    }