std::multim...insert_range(3)
π NAME π
Bestie, this is std::multimap::insert_range from the C++ Standard Library β page std::multim...insert_range(3). That's the name, 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.
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. Slay, stability. π¦
π Parameters π
rgβ a container compatible range, that is, aninput_rangewhose elements are convertible toT.
π¦ Type requirements π¦
value_typemust beEmplaceConstructibleintomultimapfrom*ranges::begin(rg). Otherwise, the behavior is undefined.
π Return value π
(none) β literally nothing comes back. It's giving void energy. π
π₯ Complexity π₯
NΒ·log(a.size() + N), where N is ranges::distance(rg).
β Notes β
Feature-test macro receipts, keep them safe:
- Feature-test macro:
__cpp_lib_containers_ranges - Value:
202202L - Std:
(C++23) - Feature:
Ranges-aware construction and insertion
π Example π
The page says // Run this code, so here's the code, bestie:
#include <iostream>
#include <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::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);
}
π« Output π«
{-2,-22} {-1,-11} {1,11} {2,22} {3,33} {3,-33} {4,44}
π See also π
- inserts elements
insert or nodesβ(since C++17)β(public member function)
Heads up, bestie: the see-also bits are exactly as cryptic as they arrived on the page. I kept every fragment. π«Ά
Source/version and date from the footer: http://cppreference.com, 2024.06.10. Bye bestie, go insert some ranges responsibly. πβ¨
π¦ 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