std::basic_ostream::swap(3)
π NAME π
Hey bestie π welcome to the std::basic_ostream::swap(3) page from the C++ Standard Libary manual. The NAME section is giving exactly this and nothing else: std::basic_ostream::swap - std::basic_ostream::swap π
β¨ Synopsis β¨
Okay so hereβs the protected king behavior, since C++11 β¨:
protected: (since C++11)
void swap( basic_ostream& rhs );
It calls basic_ios::swap(rhs) to swap all data members of the base class, except for rdbuf(), between *this and rhs π This swap function is protected: it is called by the swap functions of the swappable output stream classes std::basic_ofstream and std::basic_ostringstream, which know how to correctly swap the associated streambuffers. Periodt π«Ά
Bestie, thisswapisprotectedhere. That meansstd::cout.swap(s2);is an ERROR: swap is a protected member β literally in the example comment. No cap π
π Parameters π
rhsβ abasic_ostreamof the same type to swap with π¦
π Example π
The original has a lil // Run this code note right up top, and hereβs the code exactly, bestie:
#include <iostream>
#include <sstream>
#include <utility>
int main()
{
std::ostringstream s1("hello");
std::ostringstream s2("bye");
s1.swap(s2); // OK, ostringstream has a public swap()
std::swap(s1, s2); // OK, calls s1.swap(s2)
// std::cout.swap(s2); // ERROR: swap is a protected member
std::cout << s1.str() << '\n';
}
π Output π
And the output is literally:
hello
Mwah π this is the std::basic_ostream::swap(3) page, source/version http://cppreference.com, date 2024.06.10 β footer details delivered, bestie, not a drill π«Άπ
π¦ 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