std::swap(s...at_multimap)(3)

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

okay so bestie, welcome to the std::swap(std::flat_multimap) page from the C++ Standard Libary manual β€” yes, β€œLibary” is literally how the header spells it, iconic. The page title tag is std::swap(s...at_multimap)(3), and we are about to get into it. 🫢

πŸ’… NAME πŸ’…

std::swap(std::flat_multimap) - std::swap(std::flat_multimap). That’s the whole name, bestie, and yes it’s a little redundant but it’s serving.

✨ Synopsis ✨

Defined in header <flat_map>.

friend void swap( std::flat_multimap& lhs, std::flat_multimap& rhs )

(since C++23) and it’s noexcept; β€” the semicolon is literally right there on the page, so we’re keeping it.

This is the specialization of the std::swap algorithm for std::flat_multimap. It swaps the contents of lhs and rhs, and it calls lhs.swap(rhs). periodt. πŸ’…

🫢 Parameters 🫢

  • lhs, rhs β€” containers whose contents to swap. Both of them are containers, and their contents are the thing getting swapped. lowkey simple.

πŸ’– Return value πŸ’–

(none) β€” no return, bestie. It just does the swap and leaves. πŸŽ€

πŸ”₯ Complexity πŸ”₯

Same as swapping the underlying containers. That’s the whole complexity tea. πŸ“

πŸŽ€ Example πŸŽ€

The page says Run this code, so here’s the code exactly, no cap:

#include <algorithm>
#include <iostream>
#include <flat_map>

int main()
{
    std::flat_multimap<int, char> alice{{1, 'a'}, {2, 'b'}, {3, 'c'}};
    std::flat_multimap<int, char> bob{{7, 'Z'}, {8, 'Y'}, {9, 'X'},
{10, 'W'}};

    auto print = [](std::pair<const int, char>& n)
    {
        std::cout << ' ' << n.first << ':' << n.second;
    };

    // Print state before swap
    std::cout << "Alice:";
    std::for_each(alice.begin(), alice.end(), print);
    std::cout << "\n" "Bob  :";
    std::for_each(bob.begin(), bob.end(), print);
    std::cout << '\n';

    std::cout << "-- SWAP\n";
    std::swap(alice, bob);

    // Print state after swap
    std::cout << "Alice:";
    std::for_each(alice.begin(), alice.end(), print);
    std::cout << "\n" "Bob  :";
    std::for_each(bob.begin(), bob.end(), print);
    std::cout << '\n';
}

πŸ–¨οΈ Output: πŸ–¨οΈ

Alice: 1:a 2:b 3:c
Bob  : 7:Z 8:Y 9:X 10:W
-- SWAP
Alice: 7:Z 8:Y 9:X 10:W
Bob  : 1:a 2:b 3:c

🌈 See also 🌈

  • swap β€” swaps the contents. It’s a public member function. πŸ‘‘

okay bye bestie πŸ’– β€” this page came from source/version http://cppreference.com, dated 2024.06.10, and the footer tag is std::swap(s...at_multimap)(3). πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from