std::inplace_vector<T,N>::insert_range

Inserts, in non-reversing order, copies of elements in rg before pos.

# Declarations

template< container-compatible-range<T> R >
constexpr iterator insert_range( const_iterator pos, R&& rg );

(since C++26)

# Parameters

# Return value

An iterator that points at the copy of the first element inserted into inplace_vector or at pos if rg is empty.

# Example

#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());
    }
}

# See also