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

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

πŸ’… std::swap(s...at_multiset)(3) β€” C++ Standard Libary, section 3, bestie

okay so real talk, this page is from the C++ Standard Libary manual (section 3, the library girlies) and it's about one very specific little swap. stay with me, it's short and it's adorable.

✨ NAME ✨

std::swap(std::flat_multiset) β€” literally std::swap(std::flat_multiset), that's the whole name, she's not complicated πŸŽ€

🌸 SYNOPSIS 🌸

So the way this works, she's Defined in header <flat_set> β€” that's where she lives, that's her home address 🏠

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

(since C++23) β€” yes, she's a newer girly, C++23 and up only, don't come at her with C++17 🫢

and yup, she's noexcept; β€” no throwing, no drama, no cap πŸ’…

What she does: Specializes the std::swap algorithm for std::flat_multiset. Swaps the contents of lhs and rhs. Calls lhs.swap(rhs).

that's it. that's the tea. she just swaps. πŸ”₯

πŸ¦‹ PARAMETERS πŸ¦‹

  • lhs, rhs β€” containers whose contents to swap. (two containers, bestie, you gotta give her two β€” she's not gonna figure it out herself πŸ™ˆ)

⭐ RETURN VALUE ⭐

(none)

nothing. nada. she does the thing and dips. main character energy honestly πŸ‘‘

πŸŽ€ COMPLEXITY πŸŽ€

Same as swapping the underlying container. periodt. no extra secret complexity hidden in there, it's exactly what the underlying container's swap costs. iykyk 🀝

πŸ’– EXAMPLE πŸ’–

// Run this code

#include <algorithm>
#include <iostream>
#include <flat_set>

int main()
{
    std::flat_multiset<int> alice{1, 2, 3};
    std::flat_multiset<int> bob{7, 8, 9, 10};

    auto print = [](const int& n) { std::cout << ' ' << n; };

    // 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 2 3
Bob  : 7 8 9 10
-- SWAP
Alice: 7 8 9 10
Bob  : 1 2 3

like look at that 😭 alice and bob literally traded whole entire sets and nobody lost a single int. iconic. ate. πŸ’€βœ¨

🧚 SEE ALSO 🧚

  • swap β€” swaps the contents (public member function)

yes bestie, there's a member function version too, she's the popular one, go say hi 🫢


okay that's the page!! sourced from http://cppreference.com, dated 2024.06.10, and the footer said std::swap(s...at_multiset)(3) so we're closing the loop on that. love u, go swap something responsibly πŸ“πŸ’œπŸŒΈ

πŸ“¦ where this page comes from