std::flat_m...nsert_range(3)

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

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

🌸 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