std::basic_...m::operator=(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ¦‹ std::basic_osyncstream::operator= πŸ¦‹

okay so this is the std::basic_...m::operator=(3) page from the C++ Standard Libary manual (section 3) β€” yes, the header spells it β€œLibary,” and we are not fixing it, periodt. The full-name main character is std::basic_osyncstream::operator=, and she is literally the move-assignment operator for a synchronized output stream. πŸ’…


πŸ’– NAME πŸ’–

std::basic_osyncstream::operator= β€” std::basic_osyncstream::operator= (yes, the original NAME line is literally the same string twice, and we’re keeping that exact mirror-selfie energy). πŸͺžβœ¨

🌸 Synopsis 🌸

basic_osyncstream& operator=( std::basic_osyncstream&& other );

Since C++20 β€” this one’s been around since C++20, bestie. πŸ’–

Move-assigns a synchronized output stream: πŸ’«

  • It move-assigns the wrapped std::basic_syncbuf from the corresponding member of other. After this move-assignment, other.get_wrapped() returns a null pointer, and destruction of other produces no output; any pending buffered output will be emitted. 🫢
  • It also move-assigns the base std::basic_ostream β€” this swaps all stream state variables except rdbuf between *this and other. πŸŒ€

πŸŽ€ Parameters πŸŽ€

  • other β€” another synchronized output stream to move from. πŸ’–

πŸ‘‘ Return value πŸ‘‘

*this β€” that’s the return, periodt. πŸ’…

πŸ”₯ Example πŸ”₯

// Run this code β€” hit it, bestie:

#include <iomanip>
#include <iostream>
#include <sstream>
#include <syncstream>
#include <utility>

int main()
{
    std::osyncstream out(std::cout);
    out << "test\n";
    std::ostringstream str_out;
    std::osyncstream{str_out} = std::move(out); // Note that out is emitted here
    std::cout << "str_out = " << std::quoted(str_out.view()) << '\n';
}

⭐ Output ⭐

test
str_out = ""

🧚 Defect reports 🧚

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. πŸ’€

  • LWG 3867 β€” applied to C++20. Behavior as published: the move assignment operator was noexcept, but std::basic_syncbuf's move assignment operator is not. Correct behavior: removed noexcept. 🫠

🌈 See also 🌈

  • constructor β€” constructs a basic_osyncstream object (public member function). πŸŽ€
  • destructor β€” destroys the basic_osyncstream and emits its internal buffer (public member function). 🫢
  • emit β€” calls emit() on the underlying basic_syncbuf to transmit its internal data to the final destination (public member function). ✨

okay bestie, that’s the tea: this page came from source http://cppreference.com, version/date 2024.06.10, and the footer title is std::basic_...m::operator=(3). byeee, go move-assign something safely πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from