std::unorde...insert_range(3)
π NAME π
okay so this page is std::unordered_multiset::insert_range β and the NAME line literally says std::unordered_multiset::insert_range - std::unordered_multiset::insert_range, because why not repeat the icon herself π
. The manual is C++ Standard Libary (spelling and all), and the page tag is std::unorde...insert_range(3). Sheβs a C++23 girlie: insert_range copies a whole range into your multiset, and honestly? obsessed. π
β¨ 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. Like, every single one gets copied in. π«Ά
Each iterator in the range rg is dereferenced exactly once. The behavior is undefined if rg overlaps with the container β no cap, do not do that, thatβs the dangerous girlie behavior π.
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 yeah: rehash = iterator vibe check failed π.
π Parameters π
rgβ a container compatible range, that is, aninput_rangewhose elements are convertible toT. Basically a range thatβs compatible with the container, bestie β¨.
π¦ Type requirements π¦
value_typemust beEmplaceConstructibleintounordered_multisetfrom*ranges::begin(rg). Otherwise, the behavior is undefined. UNDEFINED, bestie β we do not play with that π.
πΈ Return value πΈ
(none) β nothing, nada, zero returns. She just does the thing and leaves π
.
β Complexity β
Average case O(N), where N is ranges::distance(rg), worst case O(NΒ·(a.size() + 1)). Math girlie said what she said π§.
π Notes π
Feature-test macro table, but make it cute:
- Feature-test macro:
__cpp_lib_containers_ranges - Value:
202202L - Std:
(C++23) - Feature: Ranges-aware construction and insertion
iykyk π.
π Example π
Run this code π
#include <iostream>
#include <unordered_set>
void println(auto, auto const& container)
{
for (const auto& elem : container)
std::cout << elem << ' ';
std::cout << '\n';
}
int main()
{
auto container = std::unordered_multiset{1, 3, 2, 4};
const auto rg = {-1, 3, -2};
#ifdef __cpp_lib_containers_ranges
container.insert_range(rg);
#else
container.insert(rg.begin(), rg.end());
#endif
println("{}", container);
}
π Possible output π
1 -2 3 3 2 -1 4
π See also π
inserts elementsinsert or nodes(since C++17)(public member function)
yep, those are the See also crumbs β preserved exactly, periodt π.
mwah π β source/version: http://cppreference.com, dated 2024.06.10, page tag std::unorde...insert_range(3). Thatβs the whole footer, bestie π«Ά.
π¦ 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