std::inplace_vector<T,N>::try_append_range
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::try_append_range
template< container-compatible-range <T> R >
constexpr std::ranges::borrowed_iterator_t <R> try_append_range( R&& rg );
(since C++26)
constexpr std::ranges::borrowed_iterator_t <R> try_append_range( R&& rg );
Appends copies of initial elements in rg before end()
, until all elements are inserted or the internal storage is exhausted (i.e. size() == capacity() is true).
All iterators and references remain valid. The end()
iterator is invalidated.
Each iterator in rg is dereferenced at most once.
[edit] Parameters
Type requirements
-
T
must be EmplaceConstructible into inplace_vector
from *ranges::begin (rg). Otherwise, the behavior is undefined.
[edit] Return value
An iterator pointing to the first element of rg that was not inserted into *this, or ranges::end (rg) if no such element exists.
[edit] Complexity
Linear in the number of elements inserted.
[edit] Exceptions
Any exception thrown by initialization of inserted element.
inplace_vector
provides the basic exception safety guarantee, i.e., all elements of the container before the call are preserved, and all already inserted elements (before the exception, if any) are also preserved.
[edit] Notes
This section is incomplete
Reason: Explain the purpose of this API.
Reason: Explain the purpose of this API.
[edit] Example
Run this code
#include <cassert> #include <initializer_list> #include <inplace_vector> int main() { using I = std::inplace_vector <int, 8>; auto nums = I{1, 2, 3}; const auto rg = {-1, -2, -3}; auto it = nums.try_append_range(rg); assert (nums.size() == 6); assert ((nums == I{1, 2, 3, -1, -2, -3})); assert (it == rg.end()); it = nums.try_append_range(rg); assert (nums.size() == 8); assert ((nums == I{1, 2, 3, -1, -2, -3, -1, -2})); assert (it == rg.begin() + 2); }