std::flat_m...nsert_range(3)
π NAME π
okay so bestie, welcome to the std::flat_m...nsert_range(3) page from the C++ Standard Libary manual (yes, thatβs the spelling in the header β we respect the typo π
). Itβs all about std::flat_multiset::insert_range, and she is main character energy, no cap.
std::flat_multiset::insert_range β std::flat_multiset::insert_range (self-titled album vibes β¨).
π¦ 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 into underlying container c as if by:
for (const auto& e : rg)
c.insert(c.end(), e);
Then, sorts the range of newly inserted elements with respect to compare. Merges the resulting sorted range and the sorted range of pre-existing elements into a single sorted range.
Each iterator in the range rg is dereferenced exactly once. The behavior is undefined if rg overlaps with the container.
β οΈ Undefined behavior warning: if rg overlaps with the container, thatβs undefined behavior. Do not do it, bestie. π«Ά
Information on iterator invalidation is copied from here.
π Parameters π
rgβ a container compatible range, that is, aninput_rangewhose elements are convertible toT.
πΈ Return value πΈ
(none) β she gives you nothing back, and honestly? Valid.
π₯ Complexity π₯
N + MΒ·log(M), where N is size() before the operation and M is ranges::distance(rg).
π Notes π
Since insert_range performs an in-place merge operation, that may allocate memory.
π Example π
// Run this code
#include <iostream>
#include <flat_set>
void println(auto, auto const& container)
{
for (const auto& elem : container)
std::cout << elem << ' ';
std::cout << '\n';
}
int main()
{
auto container = std::flat_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);
}
π Output π
-2 -1 1 2 3 3 4
π See also π
insertβ inserts elements (public member function)
mwah π source/version: http://cppreference.com, dated 2024.06.10, and the page is std::flat_m...nsert_range(3). bye bestie, go slay some ranges π§π
π¦ 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