Standard library header <inplace_vector> (C++26)

From cppreference.com
< cpp‎ | header
 
 
Standard library headers
General utilities
<any> (C++17)
<bitset>
<bit> (C++20)
<charconv> (C++17)
<expected> (C++23)
<format> (C++20)
<functional>
<optional> (C++17)
<tuple> (C++11)
<typeindex> (C++11)
<utility>
<variant> (C++17)
Containers
<array> (C++11)
<deque>
<flat_map> (C++23)
<flat_set> (C++23)
<forward_list> (C++11)
<inplace_vector> (C++26)   
<list>
<map>
<mdspan> (C++23)
<queue>
<set>
<span> (C++20)
<stack>
<unordered_map> (C++11)
<unordered_set> (C++11)
<vector>
Iterators
<iterator>
Ranges
<generator> (C++23)
<ranges> (C++20)
 

This header is part of the containers library.

Includes

(C++20)
Three-way comparison operator support
std::initializer_list class template

Classes

dynamically-resizable, fixed capacity, inplace contiguous array
(class template)

Functions

erases all elements satisfying specific criteria
(function template)

Synopsis

// 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);
}

Class template 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);
    }
  };
}