Namespaces
Variants

Standard library header <flat_set> (C++23)

From cppreference.net
Standard library headers

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

目录

包含头文件

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

(C++23)
适配容器以提供按键排序的唯一键集合
(类模板)
适配容器以提供按键排序的键集合
(类模板)
特化 std::uses_allocator 类型特征
(类模板特化)
特化 std::uses_allocator 类型特征
(类模板特化)

函数

擦除满足特定条件的所有元素
(函数模板)
擦除满足特定条件的所有元素
(函数模板)

标签

指示范围内的元素已排序且唯一
(标签)
指示范围内的元素已排序(不要求唯一性)
(标签)

概要

#include <compare>
#include <initializer_list>
namespace std {
  // 类模板 flat_set
  template<class Key, class Compare = less<Key>, class KeyContainer = vector<Key>>
  class flat_set;
  struct sorted_unique_t
  {
    explicit sorted_unique_t() = default;
  };
  inline constexpr sorted_unique_t sorted_unique{};
  template<class Key, class Compare, class KeyContainer, class Allocator>
  struct uses_allocator<flat_set<Key, Compare, KeyContainer>, Allocator>;
  // flat_set 的擦除操作
  template<class Key, class Compare, class KeyContainer, class Predicate>
  typename flat_set<Key, Compare, KeyContainer>::size_type erase_if(
    flat_set<Key, Compare, KeyContainer>& c,
    Predicate pred);
  // 类模板 flat_multiset
  template<class Key, class Compare = less<Key>, class KeyContainer = vector<Key>>
  class flat_multiset;
  struct sorted_equivalent_t
  {
    explicit sorted_equivalent_t() = default;
  };
  inline constexpr sorted_equivalent_t sorted_equivalent{};
  template<class Key, class Compare, class KeyContainer, class Allocator>
  struct uses_allocator<flat_multiset<Key, Compare, KeyContainer>, Allocator>;
  // flat_multiset 的擦除操作
  template<class Key, class Compare, class KeyContainer, class Predicate>
  typename flat_multiset<Key, Compare, KeyContainer>::size_type erase_if(
    flat_multiset<Key, Compare, KeyContainer>& c,
    Predicate pred);
}

类模板 std:: flat_set

namespace std {
  template<class Key, class Compare = less<Key>, class KeyContainer = vector<Key>>
  class flat_set
  {
  public:
    // 类型定义
    using key_type               = Key;
    using value_type             = Key;
    using key_compare            = Compare;
    using value_compare          = Compare;
    using reference              = value_type&;
    using const_reference        = const value_type&;
    using size_type              = typename KeyContainer::size_type;
    using difference_type        = typename KeyContainer::difference_type;
    using iterator               = /* 实现定义 */;
    using const_iterator         = /* 实现定义 */;
    using reverse_iterator       = std::reverse_iterator<iterator>;
    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
    using container_type         = KeyContainer;
    // 构造函数
    flat_set()
      : flat_set(key_compare())
    {
    }
    explicit flat_set(const key_compare& comp)
      : /*c*/()
      , /*compare*/(comp)
    {
    }
    explicit flat_set(container_type cont, const key_compare& comp = key_compare());
    flat_set(sorted_unique_t,
             container_type cont,
             const key_compare& comp = key_compare())
      : /*c*/(std::move(cont))
      , /*compare*/(comp)
    {
    }
    template<class InputIter>
    flat_set(InputIter first, InputIter last, const key_compare& comp = key_compare())
      : /*c*/()
      , /*compare*/(comp)
    {
      insert(first, last);
    }
    template<class InputIter>
    flat_set(sorted_unique_t,
             InputIter first,
             InputIter last,
             const key_compare& comp = key_compare())
      : /*c*/(first, last)
      , /*compare*/(comp)
    {
    }
    template<container-compatible-range<value_type> R>
    flat_set(from_range_t fr, R&& rg)
      : flat_set(fr, std::forward<R>(rg), key_compare())
    {
    }
    template<container-compatible-range<value_type> R>
    flat_set(from_range_t, R&& rg, const key_compare& comp)
      : flat_set(comp)
    {
      insert_range(std::forward<R>(rg));
    }
    flat_set(initializer_list<value_type> il, const key_compare& comp = key_compare())
      : flat_set(il.begin(), il.end(), comp)
    {
    }
    flat_set(sorted_unique_t s,
             initializer_list<value_type> il,
             const key_compare& comp = key_compare())
      : flat_set(s, il.begin(), il.end(), comp)
    {
    }
    // 带分配器的构造函数
    template<class Alloc>
    explicit flat_set(const Alloc& a);
    template<class Alloc>
    flat_set(const key_compare& comp, const Alloc& a);
    template<class Alloc>
    flat_set(const container_type& cont, const Alloc& a);
    template<class Alloc>
    flat_set(const container_type& cont, const key_compare& comp, const Alloc& a);
    template<class Alloc>
    flat_set(sorted_unique_t, const container_type& cont, const Alloc& a);
    template<class Alloc>
    flat_set(sorted_unique_t,
             const container_type& cont,
             const key_compare& comp,
             const Alloc& a);
    template<class Alloc>
    flat_set(const flat_set&, const Alloc& a);
    template<class Alloc&gt

类模板 std:: flat_multiset

namespace std {
  template<class Key, class Compare = less<Key>, class KeyContainer = vector<Key>>
  class flat_multiset
  {
  public:
    // 类型定义
    using key_type               = Key;
    using value_type             = Key;
    using key_compare            = Compare;
    using value_compare          = Compare;
    using reference              = value_type&;
    using const_reference        = const value_type&;
    using size_type              = typename KeyContainer::size_type;
    using difference_type        = typename KeyContainer::difference_type;
    using iterator               = /* 实现定义 */;
    using const_iterator         = /* 实现定义 */;
    using reverse_iterator       = std::reverse_iterator<iterator>;
    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
    using container_type         = KeyContainer;
    // 构造函数
    flat_multiset()
      : flat_multiset(key_compare())
    {
    }
    explicit flat_multiset(const key_compare& comp)
      : /*c*/()
      , /*compare*/(comp)
    {
    }
    explicit flat_multiset(container_type cont, const key_compare& comp = key_compare());
    flat_multiset(sorted_equivalent_t,
                  container_type cont,
                  const key_compare& comp = key_compare())
      : /*c*/(std::move(cont))
      , /*compare*/(comp)
    {
    }
    template<class InputIter>
    flat_multiset(InputIter first,
                  InputIter last,
                  const key_compare& comp = key_compare())
      : /*c*/()
      , /*compare*/(comp)
    {
      insert(first, last);
    }
    template<class InputIter>
    flat_multiset(sorted_equivalent_t,
                  InputIter first,
                  InputIter last,
                  const key_compare& comp = key_compare())
      : /*c*/(first, last)
      , /*compare*/(comp)
    {
    }
    template<container-compatible-range<value_type> R>
    flat_multiset(from_range_t fr, R&& rg)
      : flat_multiset(fr, std::forward<R>(rg), key_compare())
    {
    }
    template<container-compatible-range<value_type> R>
    flat_multiset(from_range_t, R&& rg, const key_compare& comp)
      : flat_multiset(comp)
    {
      insert_range(std::forward<R>(rg));
    }
    flat_multiset(initializer_list<value_type> il,
                  const key_compare& comp = key_compare())
      : flat_multiset(il.begin(), il.end(), comp)
    {
    }
    flat_multiset(sorted_equivalent_t s,
                  initializer_list<value_type> il,
                  const key_compare& comp = key_compare())
      : flat_multiset(s, il.begin(), il.end(), comp)
    {
    }
    // 带分配器的构造函数
    template<class Alloc>
    explicit flat_multiset(const Alloc& a);
    template<class Alloc>
    flat_multiset(const key_compare& comp, const Alloc& a);
    template<class Alloc>
    flat_multiset(const container_type& cont, const Alloc& a);
    template<class Alloc>
    flat_multiset(const container_type& cont, const key_compare& comp, const Alloc& a);
    template<class Alloc>
    flat_multiset(sorted_equivalent_t, const container_type& cont, const Alloc& a);
    template<class Alloc>
    flat_multiset(sorted_equivalent_t,
                  const container_type& cont,
                  const key_compare& comp,
                  const Alloc& a);
    template<class Alloc>
    flat_multiset(const flat_multiset&, const Alloc& a);
    template

参考文献

  • C++23 标准 (ISO/IEC 14882:2024):
  • 24.6.5 头文件 <flat_set> 概要 [flat.set.syn]
  • 24.6.11.2 定义 [flat.set.defn]
  • 24.6.12.2 定义 [flat.multiset.defn]