std::swap(std::multiset)(3)
π NAME π
std::swap(std::multiset) - std::swap(std::multiset)
hiii bestie π«Ά this is the std::swap(std::multiset)(3) page from the C++ Standard Libary β manual name folded in near the top, spelling and all, no boring header-line copy-paste, we ate π
.
β¨ Synopsis β¨
okay so first things first: itβs defined in header <set>, and the signatures are giving βtwo eras of C++ walked inβ π. The synopsis is exactly this, bestie:
Defined in header <set>
template< class Key, class Compare, class Alloc >
void swap( std::multiset<Key, Compare, Alloc>& lhs, (until C++17)
std::multiset<Key, Compare, Alloc>& rhs );
template< class Key, class Compare, class Alloc >
void swap( std::multiset<Key, Compare, Alloc>& lhs, (since C++17)
std::multiset<Key, Compare, Alloc>& rhs )
noexcept(/* see below */);
so whatβs the tea β β this specializes the std::swap algorithm for std::multiset. It swaps the contents of lhs and rhs. And it does that by calling lhs.swap(rhs). periodt π
.
πΈ Parameters πΈ
lhs,rhsβ containers whose contents to swap
thatβs the whole parameter list, bestie: two containers and a dream π.
π Return value π
(none) β literally none, bestie. it returns nothing and itβs iconic for it π
.
π¦ Complexity π¦
Constant. no cap, thatβs the whole complexity note β constant, periodt β¨.
π Exceptions π
the noexcept specification is this, and itβs since C++17 bestie:
noexcept specification: (since C++17)
noexcept(noexcept(lhs.swap(rhs)))
π Example π
okay this example is lowkey the moment π β Alice and Bob are both std::multiset<int>, and weβre swapping them. Copy it exactly, bestie:
// Run this code
#include <algorithm>
#include <iostream>
#include <set>
int main()
{
std::multiset<int> alice{1, 2, 3};
std::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
π«Ά See also π«Ά
swapβ swaps the contents (public member function)
π§ Category π§
- conditionally noexcept
okay thatβs the page, bestie π«Ά source/version: http://cppreference.com; date: 2024.06.10; footer page name: std::swap(std::multiset)(3). 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