std::unorde...insert_range(3)

๐Ÿ“ฆ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

๐ŸŒธ NAME ๐ŸŒธ

std::unordered_multimap::insert_range โ€” std::unordered_multimap::insert_range. yep, it says it twice and we respect it ๐Ÿ’… this page is std::unorde...insert_range(3) from the C++ Standard Libary manual, bestie โ€” yes, that's the spelling up top, 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. cute, simple, doing the most in the best way ๐Ÿซถ

Each iterator in the range rg is dereferenced exactly once. The behavior is undefined if rg overlaps with the container. ๐Ÿšจ

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 likeโ€ฆ pay attention to your iterators, bestie ๐Ÿ˜ญ


๐ŸŽ€ 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 unordered_multimap from *ranges::begin(rg). Otherwise, the behavior is undefined. ๐Ÿซ 

๐Ÿซถ Return value ๐Ÿซถ

(none) โ€” literally none, bestie ๐Ÿ’€


๐Ÿ”ฅ Complexity ๐Ÿ”ฅ

Average case O(N), where N is ranges::distance(rg), worst case O(Nยท(a.size() + 1)). math girlie behavior, honestly ๐Ÿงฎโœจ


๐Ÿงš Notes ๐Ÿงš

Feature-test macro tea โ˜•:

  • __cpp_lib_containers_ranges โ€” Value: 202202L; Std: (C++23); Feature: Ranges-aware construction and insertion.

๐ŸŒˆ Example ๐ŸŒˆ

The page literally says // Run this code, so here's the code, untouched:

        #include <iostream>
        #include <unordered_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::unordered_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);
        }

โญ Possible output โญ

{1,11} {-2,-22} {3,-33} {3,33} {2,22} {-1,-11} {4,44}

๐Ÿ‘‘ See also ๐Ÿ‘‘

  • inserts elements โ€” insert or nodes (since C++17) (public member function)

okay that's the whole page, bestie! source/version: http://cppreference.com ยท date: 2024.06.10 ยท page: std::unorde...insert_range(3) ๐Ÿซถ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from