标准库标头 <inplace_vector> (C++26)

来自cppreference.com
< cpp‎ | header


 
 
标准库标头
语言支持
概念
<concepts> (C++20)
诊断
<system_error> (C++11)

内存管理
<memory_resource> (C++17)  
元编程
<type_traits> (C++11)
<ratio> (C++11)
通用工具
<utility>
<tuple> (C++11)
<optional> (C++17)
<variant> (C++17)
<any> (C++17)
<debugging> (C++26)
<expected> (C++23)
<bitset>
<charconv> (C++17)
<format> (C++20)
<bit> (C++20)

字符串
<cuchar> (C++11)

容器
<flat_set> (C++23)
<span> (C++20)
<mdspan> (C++23)
<inplace_vector> (C++26)
迭代器
<iterator>
范围
<ranges> (C++20)
<generator> (C++23)
算法
数值
<cfenv> (C++11)
<complex>
<cmath>
<linalg> (C++26)
<numbers> (C++20)

日期时间
<chrono> (C++11)
本地化
<codecvt> (C++11/17/26*)
<text_encoding> (C++26)
输入/输出
<filesystem> (C++17)
<cstdio>
<cinttypes> (C++11)
<strstream> (C++98/26*)
正则表达式
<regex> (C++11)
并发支持
<stop_token> (C++20)
<thread> (C++11)
<atomic> (C++11)
<rcu> (C++26)
<stdatomic.h> (C++23)
<mutex> (C++11)
<shared_mutex> (C++14)

<condition_variable> (C++11)  
<semaphore> (C++20)
<latch> (C++20)

<barrier> (C++20)
<future> (C++11)
<hazard_pointer> (C++26)

C 兼容
<cstdbool> (C++11/17/20*)  
<ccomplex> (C++11/17/20*)
<ctgmath> (C++11/17/20*)

<cstdalign> (C++11/17/20*)

<ciso646> (C++20 前)

 

此标头是容器库的一部分。

包含

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

可动态调整大小的固定容量原位连续数组
(类模板)

函数

擦除所有满足特定判别标准的元素
(函数模板)

概要

#include <compare>
#include <initializer_list>
 
namespace std {
  // 类模板 inplace_vector
  template<class T, std::size_t N>
    class inplace_vector; // partially freestanding
 
  // inplace_vector 的擦除
  template<class T, std::size_t N, class U>
  constexpr typename inplace_vector<T, N>::size_type
    erase(inplace_vector<T, N>& c, const U& value);
 
  template<class T, std::size_t N, class Predicate>
  constexpr typename inplace_vector<T, N>::size_type
    erase_if(inplace_vector<T, N>& c, Predicate pred);
}

类模板 std::inplace_vector

namespace std {
  template<class T, std::size_t N>
  class inplace_vector {
  public:
    // 类型:
    using value_type             = T;
    using pointer                = T*;
    using const_pointer          = const T*;
    using reference              = value_type&;
    using const_reference        = const value_type&;
    using size_type              = std::size_t;                 
    using difference_type        = std::ptrdiff_t;             
    using iterator               = /* 由实现定义 */;
    using const_iterator         = /* 由实现定义 */;
    using reverse_iterator       = std::reverse_iterator<iterator>;
    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
 
    // 构造/复制/析构
    constexpr inplace_vector() noexcept;
    // freestanding-deleted
    constexpr explicit inplace_vector(size_type n); 
    // freestanding-deleted
    constexpr inplace_vector(size_type n, const T& value); 
    // freestanding-deleted
    template <class InputIterator>
      constexpr inplace_vector(InputIterator first, InputIterator last); 
    // freestanding-deleted
    template <container-compatible-range<T> R>
      constexpr inplace_vector(std::from_range_t, R&& rg); 
    constexpr inplace_vector(const inplace_vector&);
    constexpr inplace_vector(inplace_vector&&)
      noexcept(N == 0 || std::is_nothrow_move_constructible_v<T>);
    // freestanding-deleted
    constexpr inplace_vector(std::initializer_list<T> il); 
    constexpr ~inplace_vector();
    constexpr inplace_vector& operator=(const inplace_vector& other);
    constexpr inplace_vector& operator=(inplace_vector&& other)
      noexcept(N == 0 || 
              (std::is_nothrow_move_assignable_v<T> &&
               std::is_nothrow_move_constructible_v<T>));
    // freestanding-deleted
    constexpr inplace_vector& operator=(std::initializer_list<T>); 
    // freestanding-deleted
    template <class InputIterator>
      constexpr void assign(InputIterator first, InputIterator last); 
    template<container-compatible-range<T> R>
      constexpr void assign_range(R&& rg); // freestanding-deleted
    constexpr void assign(size_type n, const T& u); // freestanding-deleted
    constexpr void assign(std::initializer_list<T> il); // freestanding-deleted
 
    // 迭代器
    constexpr iterator               begin()         noexcept;
    constexpr const_iterator         begin()   const noexcept;
    constexpr iterator               end()           noexcept;
    constexpr const_iterator         end()     const noexcept;
    constexpr reverse_iterator       rbegin()        noexcept;
    constexpr const_reverse_iterator rbegin()  const noexcept;
    constexpr reverse_iterator       rend()          noexcept;
    constexpr const_reverse_iterator rend()    const noexcept;
 
    constexpr const_iterator         cbegin()  const noexcept;
    constexpr const_iterator         cend()    const noexcept;
    constexpr const_reverse_iterator crbegin() const noexcept;
    constexpr const_reverse_iterator crend()   const noexcept;
 
    // 大小/容量
    constexpr bool empty() const noexcept;
    constexpr size_type size() const noexcept;
    static constexpr size_type max_size() noexcept;
    static constexpr size_type capacity() noexcept;
    constexpr void resize(size_type sz); // freestanding-deleted
    constexpr void resize(size_type sz, const T& c); // freestanding-deleted
    static constexpr void reserve(size_type n); // freestanding-deleted
    static constexpr void shrink_to_fit() noexcept;
 
    // 元素访问
    constexpr reference       operator[](size_type n);
    constexpr const_reference operator[](size_type n) const;
    constexpr const_reference at(size_type n) const; // freestanding-deleted
    constexpr reference       at(size_type n); // freestanding-deleted
    constexpr reference       front();
    constexpr const_reference front() const;
    constexpr reference       back();
    constexpr const_reference back() const;
 
    // 数据访问
    constexpr       T* data()       noexcept;
    constexpr const T* data() const noexcept;
 
    // 修改器
    template <class... Args> constexpr reference emplace_back(Args&&... args); 
      // freestanding-deleted
    constexpr reference push_back(const T& x); // freestanding-deleted
    constexpr reference push_back(T&& x); // freestanding-deleted
    template<container-compatible-range<T> R>
      constexpr void append_range(R&& rg); // freestanding-deleted
    constexpr void pop_back();
 
    template<class... Args>
      constexpr pointer try_emplace_back(Args&&... args);
    constexpr pointer try_push_back(const T& x);
    constexpr pointer try_push_back(T&& x);
    template<container-compatible-range<T> R>
      constexpr ranges::borrowed_iterator_t<R> try_append_range(R&& rg);
 
    template<class... Args>
      constexpr reference unchecked_emplace_back(Args&&... args);
    constexpr reference unchecked_push_back(const T& x);
    constexpr reference unchecked_push_back(T&& x);
 
    // freestanding-deleted
    template <class... Args>
      constexpr iterator emplace(const_iterator position, Args&&... args); 
    // freestanding-deleted
    constexpr iterator insert(const_iterator position, const T& x); 
    // freestanding-deleted
    constexpr iterator insert(const_iterator position, T&& x); 
    // freestanding-deleted
    constexpr iterator insert(const_iterator position, size_type n, const T& x); 
    // freestanding-deleted
    template <class InputIterator>
      constexpr iterator insert(const_iterator position,
                                InputIterator first, InputIterator last);
    // freestanding-deleted
    template<container-compatible-range<T> R>
      constexpr iterator insert_range(const_iterator position, R&& rg); 
    // freestanding-deleted
    constexpr iterator insert(const_iterator position, std::initializer_list<T> il); 
    constexpr iterator erase(const_iterator position);
    constexpr iterator erase(const_iterator first, const_iterator last);
    constexpr void swap(inplace_vector& x)
      noexcept(N == 0 || 
              (std::is_nothrow_swappable_v<T> &&
               std::is_nothrow_move_constructible_v<T>));
    constexpr void clear() noexcept;
 
    constexpr friend bool operator==(const inplace_vector& x, const inplace_vector& y);
    constexpr friend synth-three-way-result<T>
      operator<=>(const inplace_vector& x, const inplace_vector& y);
    constexpr friend void swap(inplace_vector& x, inplace_vector& y)
      noexcept(N == 0 || 
              (std::is_nothrow_swappable_v<T> &&
               std::is_nothrow_move_constructible_v<T>))
      { x.swap(y); }
  };
}