From cppreference.com
template<container-compatible-range<value_type>R>voidinsert_range(R&&rg);(since C++23)Inserts a copy of each element in the range rg.
Each iterator in the range rg is dereferenced exactly once. The behavior is undefined if rg overlaps with the container.
No iterators or references are invalidated.
Parameters
Complexity
N·log(a.size()+N), where N is ranges::distance(rg).
Notes
macroValueStdFeature
(C++23)
construction and insertion Example
Run this code
#include<iostream>#include<map>#include<utility>voidprintln(auto,autoconst&container){for(constauto&[key,value]:container)std::cout<<'{'<<key<<','<<value<<'}'<<' ';std::cout<<'\n';}intmain(){autocontainer=std::multimap{std::pair{1,11},{3,33},{2,22},{4,44}};constautorg={std::pair{-1,-11},{3,-33},{-2,-22}};#ifdef __cpp_lib_containers_rangescontainer.insert_range(rg);#elsecontainer.insert(rg.begin(),rg.end());#endifprintln("{}",container);}Output:
{-2,-22} {-1,-11} {1,11} {2,22} {3,33} {3,-33} {4,44} See also
inserts elements or nodes(since C++17)
(public member function)