std::inplace_vector<T,N>::insert_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::insert_range
template< container-compatible-range <T> R >
constexpr iterator insert_range( const_iterator pos, R&& rg );
 
 (since C++26)
constexpr iterator insert_range( const_iterator pos, R&& rg );
Inserts, in non-reversing order, copies of elements in rg before pos.
 This section is incomplete 
Each iterator in the range rg is dereferenced exactly once.
If rg overlaps with *this, the behavior is undefined.
[edit] Parameters
 pos
 -
 iterator before which the content will be inserted (pos may be the 
end() iterator)
 Type requirements
 -If any of the following conditions is satisfied, the behavior is undefined:
-  Tis not EmplaceConstructible intoinplace_vectorfrom *ranges::begin (rg).
-  Tis not MoveInsertable intoinplace_vector.
-  Tdoes not satisfy the requirements of MoveConstructible, MoveAssignable, or Swappable.
 
-  
[edit] Return value
An iterator to the first element inserted into *this, or pos if rg is empty.
Exceptions
- std::bad_alloc , if ranges::distance (rg) + size() > capacity(). The elements of *this are not modified.
-  Any exception thrown by insertion (i.e. by copy/move constructor, move/copy assignment operator of T) or by any LegacyInputIterator operation. The elements of *this in the range[0,pos)are not modified.
[edit] Example
Run this code
#include <cassert> #include <inplace_vector> #include <iterator> #include <new> #include <print> int main() { auto v = std::inplace_vector <int, 8>{0, 1, 2, 3}; auto pos = std::next (v.begin(), 2); assert (*pos == 2); const auto rg = {-1, -2, -3}; v.insert_range(pos, rg); std::println ("{}", v); try { assert (v.size() + rg.size() > v.capacity()); v.insert_range(pos, rg); // throws: no space } catch(const std::bad_alloc & ex) { std::println ("{}", ex.what()); } }
Possible output:
[0, 1, -1, -2, -3, 2, 3] std::bad_alloc