std::basic_...m::operator=(3)
β¨ NAME β¨
okay so bestie, this is the page for std::basic_ostream::operator=. Itβs from the C++ Standard Libary manual (the header spells it C++ Standard Libary, not Library, and the truncated title is std::basic_...m::operator=(3) β iykyk π). The NAME is literally:
std::basic_ostream::operator= - std::basic_ostream::operator=
π Synopsis π
Hereβs the exact synopsis vibe, bestie:
protected: (1)
basic_ostream& operator=( const basic_ostream& rhs ) = delete;
protected: (2)
(since C++11)
basic_ostream& operator=( basic_ostream&& rhs );
- Overload (1) is the copy assignment operator. Itβs protected and itβs deleted. Output streams are not
CopyAssignable. π No copy-assigning your streams, bestie. - Overload (2) is the move assignment operator, and itβs since C++11. It exchanges all data members of the base class, except for
rdbuf(), withrhs, as if by callingswap(*rhs). This move assignment operator is also protected: it is only called by the move assignment operators of the derived movable output stream classesstd::basic_ofstreamandstd::basic_ostringstream, which know how to correctly move-assign the associated streambuffers. slay.
π Parameters π
rhsβ thebasic_ostreamobject from which to assign to*this.
π¦ Example π¦
okay, hereβs the code bestie:
// Run this code
#include <iostream>
#include <sstream>
#include <utility>
int main()
{
std::ostringstream s;
// std::cout = s; // ERROR: copy assignment operator is deleted
// std::cout = std::move(s); // ERROR: move assignment operator is protected
s = std::move(std::ostringstream() << 42); // OK, moved through derived
std::cout << s.str() << '\n';
}
π Output: π
42
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
LWG 2067 - Applied to:
C++11 - Behavior as published:
- the parameter type of overload (1) was
basic_ostream& - the parameter type of overload (2) was
const basic_ostream&&
- the parameter type of overload (1) was
- Correct behavior:
- added
const - removed
const
- added
π source/version: http://cppreference.com β’ date: 2024.06.10 β’ page: std::basic_...m::operator=(3) β okay bye bestie, go slay those streams! π
β¨
π¦ 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