std::swap(std::tuple)(3)
π std::swap(std::tuple) β C++ Standard Libary manual π
Okay so this is the std::swap(std::tuple)(3) page from the C++ Standard Libary manual (yes, the header spells it βLibary,β and we are respecting the iconβs typo ππ
). Itβs the tuple-swap situation, and itβs giving βsmall function, big main character energy.β Letβs go, bestie. β¨
πΈ NAME πΈ
std::swap(std::tuple) β std::swap(std::tuple)
Yes, the name is literally the name. We love a self-aware queen. π
π SYNOPSIS π
Defined in header <tuple>:
template< class... Types >
void swap( std::tuple<Types...>& lhs,
std::tuple<Types...>& rhs ) noexcept(/* see below */);
(since C++11) (until C++20)
template< class... Types >
constexpr void swap( std::tuple<Types...>& lhs,
std::tuple<Types...>& rhs ) noexcept(/* see below */);
(1) (since C++20)
template< class... Types >
constexpr void swap( const std::tuple<Types...>& lhs,
const std::tuple<Types...>& rhs ) noexcept(/* see below */);
(2) (since C++23)
Swaps the contents of lhs and rhs. Equivalent to lhs.swap(rhs). Periodt. π
- This overload participates in overload resolution only if
std::is_swappable_v<Ti>istruefor allifrom0tosizeof...(Types). - This overload participates in overload resolution only if
std::is_swappable_v<const Ti>istruefor allifrom0tosizeof...(Types).(since C++17)
π§Έ PARAMETERS π§Έ
lhs,rhsβ tuples whose contents to swap.
π RETURN VALUE π
(none) β literally nothing, bestie. Itβs a return-nothing situation. π«Ά
π¨ EXCEPTIONS π¨
noexcept specification:
noexcept(noexcept(lhs.swap(rhs)))
Thatβs the whole spec, no cap. π₯
π EXAMPLE π
Run this code, bestie:
// Run this code
#include <iostream>
#include <string>
#include <tuple>
int main()
{
std::tuple<int, std::string, float> p1{42, "ABCD", 2.71}, p2;
p2 = std::make_tuple(10, "1234", 3.14);
auto print_p1_p2 = [&](auto rem)
{
std::cout << rem
<< "p1 = {" << std::get<0>(p1)
<< ", " << std::get<1>(p1)
<< ", " << std::get<2>(p1) << "}, "
<< "p2 = {" << std::get<0>(p2)
<< ", " << std::get<1>(p2)
<< ", " << std::get<2>(p2) << "}\n";
};
print_p1_p2("Before p1.swap(p2): ");
p1.swap(p2);
print_p1_p2("After p1.swap(p2): ");
swap(p1, p2);
print_p1_p2("After swap(p1, p2): ");
}
π₯οΈ OUTPUT π₯οΈ
Before p1.swap(p2): p1 = {42, ABCD, 2.71}, p2 = {10, 1234, 3.14}
After p1.swap(p2): p1 = {10, 1234, 3.14}, p2 = {42, ABCD, 2.71}
After swap(p1, p2): p1 = {42, ABCD, 2.71}, p2 = {10, 1234, 3.14}
π SEE ALSO π
swapβ swaps the contents of two tuples (public member function).std::swap(std::pair)β specializes thestd::swapalgorithm (C++11) (function template).
π·οΈ CATEGORY π·οΈ
* conditionally noexcept
Okay bestie, thatβs the whole page! Source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::swap(std::tuple)(3). Bye and slay 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