std::unorde...insert_range(3)
๐ธ NAME ๐ธ
std::unordered_multimap::insert_range โ std::unordered_multimap::insert_range. yep, it says it twice and we respect it ๐
this page is std::unorde...insert_range(3) from the C++ Standard Libary manual, bestie โ yes, that's the spelling up top, no cap ๐
โจ Synopsis โจ
template< container-compatible-range<value_type> R > (since C++23)
void insert_range( R&& rg );
Inserts a copy of each element in the range rg. cute, simple, doing the most in the best way ๐ซถ
Each iterator in the range rg is dereferenced exactly once. The behavior is undefined if rg overlaps with the container. ๐จ
If after the operation the new number of elements is greater than old max_load_factor() * bucket_count() a rehashing takes place. If rehashing occurs (due to the insertion), all iterators are invalidated. Otherwise (no rehashing), iterators are not invalidated. so likeโฆ pay attention to your iterators, bestie ๐ญ
๐ Parameters ๐
rgโ a container compatible range, that is, aninput_rangewhose elements are convertible toT.
๐ Type requirements ๐
value_typemust beEmplaceConstructibleintounordered_multimapfrom*ranges::begin(rg). Otherwise, the behavior is undefined. ๐ซ
๐ซถ Return value ๐ซถ
(none) โ literally none, bestie ๐
๐ฅ Complexity ๐ฅ
Average case O(N), where N is ranges::distance(rg), worst case O(Nยท(a.size() + 1)). math girlie behavior, honestly ๐งฎโจ
๐ง Notes ๐ง
Feature-test macro tea โ:
__cpp_lib_containers_rangesโ Value:202202L; Std: (C++23); Feature: Ranges-aware construction and insertion.
๐ Example ๐
The page literally says // Run this code, so here's the code, untouched:
#include <iostream>
#include <unordered_map>
#include <utility>
void println(auto, auto const& container)
{
for (const auto& [key, value] : container)
std::cout << '{' << key << ',' << value << '}' << ' ';
std::cout << '\n';
}
int main()
{
auto container = std::unordered_multimap{std::pair{1, 11}, {3, 33},
{2, 22}, {4, 44}};
const auto rg = {std::pair{-1, -11}, {3, -33}, {-2, -22}};
#ifdef __cpp_lib_containers_ranges
container.insert_range(rg);
#else
container.insert(rg.begin(), rg.end());
#endif
println("{}", container);
}
โญ Possible output โญ
{1,11} {-2,-22} {3,-33} {3,33} {2,22} {-1,-11} {4,44}
๐ See also ๐
- inserts elements โ
insert or nodes(since C++17) (public member function)
okay that's the whole page, bestie! source/version: http://cppreference.com ยท date: 2024.06.10 ยท page: std::unorde...insert_range(3) ๐ซถ๐โจ
๐ฆ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms