std::swap(s...at_multimap)(3)
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
- 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