std::multim...insert_range(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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, an input_range whose elements are convertible to T.

πŸ¦‹ Type requirements πŸ¦‹

  • value_type must be EmplaceConstructible into multimap from *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