std::swap(s...at_multiset)(3)
π 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms