std::swap(s...d_multiset)(3)
πΈ NAME πΈ
std::swap(std::unordered_multiset) β yeah bestie, that's literally the whole name, it's std::swap(std::unordered_multiset). No notes. π
(This is page 3 of the C++ Standard Library section, btw, iykyk.)
β¨ Synopsis β¨
Ok so first thing: this whole thing lives in the header <unordered_set> π«Ά
Here's the first overload, and she's been around a minute β (since C++11) β and the version without the noexcept biz has been (until C++17), so keep that in mind:
template< class Key, class Hash, class KeyEqual, class Alloc >
void swap( std::unordered_multiset<Key, Hash, KeyEqual, Alloc>& lhs,
std::unordered_multiset<Key, Hash, KeyEqual, Alloc>& rhs
);
And then (since C++17) we got the glow-up version that tells you about exceptions up front:
template< class Key, class Hash, class KeyEqual, class Alloc >
void swap( std::unordered_multiset<Key, Hash, KeyEqual, Alloc>& lhs,
std::unordered_multiset<Key, Hash, KeyEqual, Alloc>& rhs )
noexcept(/* see below */);
So what's the tea? This specializes the std::swap algorithm for std::unordered_multiset π It swaps the contents of lhs and rhs, and under the hood it just calls lhs.swap(rhs). That's it. That's the whole vibe. β¨
π Parameters π
lhs,rhsβ the containers whose contents we're swapping. The two besties exchanging fits. π―ββοΈ
π Return value π
(none) β she gives you nothing back, because the swapping was the gift. π
π₯ Complexity π₯
Constant. Not me being obsessed with how fast that is. β‘
π Exceptions π
The noexcept specification, (since C++17):
noexcept(noexcept(lhs.swap(rhs)))
That's it, that's the whole clause, fr fr. π«Ά
π¦ Example π¦
Run this code πββοΈ
#include <algorithm>
#include <iostream>
#include <unordered_set>
int main()
{
std::unordered_multiset<int> alice{1, 2, 3};
std::unordered_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';
}
Like, Alice and Bob are literally trading whole entire containers, iconic behavior honestly. π
π Possible output π
Alice: 1 2 3
Bob : 7 8 9 10
-- SWAP
Alice: 7 8 9 10
Bob : 1 2 3
Not them fully switching lives ππ
π See also π
swapβ swaps the contents (public member function)
β Category β
- conditionally noexcept
and that's the whole page, bestie, you ate that π
Sign-off time π This little masterpiece lives over at http://cppreference.com, dated 2024.06.10 β go say hi, mwah ππ§
π¦ 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