命名空间
变体
操作

标准库头文件 <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)
三路比较运算符 支持[edit]
std::initializer_list 类模板[edit]

动态可调整大小的、固定容量的、就地连续数组
(类模板) [edit]

函数

删除所有满足特定条件的元素
(函数模板) [编辑]

[编辑] 概述

// mostly freestanding
#include <compare>
#include <initializer_list>
 
namespace std {
  // class template inplace_vector
  template<class T, size_t N>
  class inplace_vector; // partially freestanding
 
  // erasure
  template<class T, size_t N, class U = T>
  constexpr typename inplace_vector<T, N>::size_type erase(inplace_vector<T, N>& c,
                                                           const U& value);
  template<class T, 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, size_t N>
  class inplace_vector
  {
  public:
    // types:
    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              = size_t;
    using difference_type        = ptrdiff_t;
    using iterator               = /* implementation-defined */;
    using const_iterator         = /* implementation-defined */;
    using reverse_iterator       = std::reverse_iterator<iterator>;
    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
 
    // construct/copy/destroy
    constexpr inplace_vector() noexcept;
    constexpr explicit inplace_vector(size_type n);        // freestanding-deleted
    constexpr inplace_vector(size_type n, const T& value); // freestanding-deleted
    template<class InputIter>
    constexpr inplace_vector(InputIter first, InputIter last); // freestanding-deleted
    template<container-compatible-range<T> R>
    constexpr inplace_vector(from_range_t, R&& rg); // freestanding-deleted
    constexpr inplace_vector(const inplace_vector&);
    constexpr inplace_vector(inplace_vector&&) noexcept(
      N == 0 || is_nothrow_move_constructible_v<T>);
    constexpr inplace_vector(initializer_list<T> il); // freestanding-deleted
    constexpr ~inplace_vector();
    constexpr inplace_vector& operator=(const inplace_vector& other);
    constexpr inplace_vector& operator=(inplace_vector&& other) noexcept(
      N == 0 || (is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>));
    constexpr inplace_vector& operator=(initializer_list<T>); // freestanding-deleted
    template<class InputIter>
    constexpr void assign(InputIter first, InputIter last); // freestanding-deleted
    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(initializer_list<T> il);  // freestanding-deleted
 
    // iterators
    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;
 
    // size/capacity
    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;
 
    // element access
    constexpr reference operator[](size_type n);
    constexpr const_reference operator[](size_type n) const;
    constexpr reference at(size_type n);             // freestanding-deleted
    constexpr const_reference at(size_type n) const; // freestanding-deleted
    constexpr reference front();
    constexpr const_reference front() const;
    constexpr reference back();
    constexpr const_reference back() const;
 
    // data access
    constexpr T* data() noexcept;
    constexpr const T* data() const noexcept;
 
    // modifiers
    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);
 
    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, // freestanding-deleted
                              const T& x);
    template<class InputIter>
    constexpr iterator insert(const_iterator position, // freestanding-deleted
                              InputIter first,
                              InputIter last);
    template<container-compatible-range<T> R>
    constexpr iterator insert_range(const_iterator position,
                                    R&& rg);           // freestanding-deleted
    constexpr iterator insert(const_iterator position, // freestanding-deleted
                              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 ||
                                                    (is_nothrow_swappable_v<T> &&
                                                     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 || (is_nothrow_swappable_v<T> && is_nothrow_move_constructible_v<T>))
    {
      x.swap(y);
    }
  };
}