std::swap(std::flat_map)(3)
π std::swap(std::flat_map) π
okay bestie, this page comes from the C++ Standard Libary manual β yes, that's the manual name, typo and all, and we're keeping it π
. It's the std::swap page for std::flat_map, and it's here to spill exactly how the swapping works. No cap.
β¨ NAME β¨
std::swap(std::flat_map) β literally std::swap(std::flat_map).
πΈ Synopsis πΈ
Defined in header <flat_map>.
friend void swap( std::flat_map& lhs, std::flat_map& rhs ) noexcept;
(since C++23)
Specializes the std::swap algorithm for std::flat_map. Swaps the contents of lhs and rhs. Calls lhs.swap(rhs).
π Parameters π
lhs,rhsβ containers whose contents to swap.
π¦ Return value π¦
(none) β yep, nothing, zero, no return value. It just does the swap.
π Complexity π
Same as swapping the underlying containers.
π₯ Example π₯
// Run this code
#include <algorithm>
#include <iostream>
#include <flat_map>
int main()
{
std::flat_map<int, char> alice{{1, 'a'}, {2, 'b'}, {3, 'c'}};
std::flat_map<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 (public member function).
source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::swap(std::flat_map)(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