A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../../cpp/container/inplace_vector/assign_range.html below:

std::inplace_vector<T,N>::assign_range - cppreference.com

Replaces elements in the container with a copy of each element in rg.

Each iterator in the range rg is dereferenced exactly once.

If rg overlaps with *this, the behavior is undefined.

[edit] Parameters Exceptions [edit] Example
#include <algorithm>
#include <cassert>
#include <initializer_list>
#include <inplace_vector>
#include <iostream>
#include <new>
 
int main()
{
    const auto source = {1, 2, 3};
    std::inplace_vector<int, 4> destination{4, 5};
    destination.assign_range(source);
    assert(std::ranges::equal(destination, source));
 
    try
    {
        const auto bad = {-1, -2, -3, -4, -5};
        destination.assign_range(bad); // throws: bad.size() > destination.capacity()
    }
    catch(const std::bad_alloc& ex)
    {
        std::cout << ex.what() << '\n';
    }
}

Possible output:

[edit] See also inserts a range of elements
(public member function) adds a range of elements to the end
(public member function) assigns values to the container
(public member function) assigns values to the container
(public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4