std::inplace_vector<T,N>::reserve
From cppreference.com
< cpp | container | inplace vector
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Containers library
(C++17)
(C++11)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++23)
(C++23)
(C++20)
(C++23)
Tables
std::inplace_vector
inplace_vector::reserve
static constexpr void reserve( size_type new_cap );
(since C++26)
Does nothing, except that may throw std::bad_alloc . The request to increase the capacity (i.e., the internal storage size) is ignored because std::inplace_vector <T, N> is a fixed-capacity container.
[edit] Parameters
new_cap
-
new capacity of the
inplace_vector
, in number of elements
[edit] Return value
(none)
[edit] Complexity
Constant.
[edit] Exceptions
std::bad_alloc if new_cap > capacity() is true.
[edit] Notes
This function exists for compatibility with vector-like interfaces.
[edit] Example
Run this code
#include <cassert> #include <inplace_vector> #include <iostream> int main() { std::inplace_vector <int, 4> v{1, 2, 3}; assert (v.capacity() == 4 && v.size() == 3); v.reserve(2); // does nothing assert (v.capacity() == 4 && v.size() == 3); try { v.reserve(13); // throws, because requested capacity > N; v is left unchanged } catch(const std::bad_alloc & ex) { std::cout << ex.what() << '\n'; } assert (v.capacity() == 4 && v.size() == 3); }
Possible output:
std::bad_alloc
[edit] See also
[static]
(public static member function) [edit]