std::basic_stringbuf::swap(3)
π std::basic_stringbuf::swap(3) π
hey bestie, welcome to the C++ Standard Libary page for std::basic_stringbuf::swap(3) β yes, that's the manual name right there, and we are gonna get through it together π«Ά
πΈ NAME πΈ
std::basic_stringbuf::swap - std::basic_stringbuf::swap
okay so the NAME is literally just the same thing twice, and honestly? iconic. no notes π
β¨ Synopsis β¨
here's the signature tea β β and yes, the version notes matter:
void swap( basic_stringbuf& rhs );β(since C++11)(until C++20)void swap( basic_stringbuf& rhs ) noexcept(/* see below */);β(since C++20)
Swaps the state and the contents of *this and rhs.
π¨ UB ALERT, bestie: the behavior is undefined ifAllocatordoes not propagate on swap and(since C++11)the allocators of*thisandotherare unequal. that's a hard no-cap "do not do this" situation π
π Parameters π
rhsβ anotherbasic_stringbuf
π Return value π
(none)
literally nothing comes back. it's giving "the swap was the reward" β¨
π₯ Exceptions π₯
(since C++11)(until C++20)β May throw implementation-defined exceptions.(since C++20)β noexcept specification:
noexcept(std::allocator_traits<Allocator>::propagate_on_container_swap::value || std::allocator_traits<Allocator>::is_always_equal::value)
π¦ Notes π¦
This function is called automatically when swapping std::stringstream objects. It is rarely necessary to call it directly.
so likeβ¦ it's doing its thing behind the scenes, main character energy, you usually don't need to bother it π
π Example π
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
int main()
{
std::istringstream one("one");
std::ostringstream two("two");
std::cout << "Before swap: one = " << std::quoted(one.str())
<< ", two = " << std::quoted(two.str()) << ".\n";
one.rdbuf()->swap(*two.rdbuf());
std::cout << "After swap: one = " << std::quoted(one.str())
<< ", two = " << std::quoted(two.str()) << ".\n";
}
π Output: π
Before swap: one = "one", two = "two".
After swap: one = "two", two = "one".
π See also π
constructorβ constructs abasic_stringbufobject (public member function)swap(C++11)β swaps two string streams (public member function ofstd::basic_stringstream<CharT,Traits,Allocator>)
β Category β
conditionally noexcept
okay that's the whole page, mwah π β source/version: http://cppreference.com, date: 2024.06.10, page: std::basic_stringbuf::swap(3). bye bestie, go swap something cute π«Ά
π¦ 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