std::ostrea...::operator=(3)

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

✨ std::ostrea...::operator=(3) ✨

okay so welcome to std::ostrea...::operator=(3), straight out of the C++ Standard Libary manual, bestie. This is the page for the assignment operator on std::ostream_iterator, and yes it’s giving β€œtiny operator, big stream energy” πŸ’…. Let’s get into it.

🌸 NAME 🌸

std::ostream_iterator::operator= β€” std::ostream_iterator::operator=

fr fr, that’s the name. Nothing extra, just iconic repetition 🫢.

πŸ¦‹ Synopsis πŸ¦‹

ostream_iterator& operator=( const ostream_iterator& ); (1)
ostream_iterator& operator=( const T& value );          (2)
  • (1) Copy assignment operator. Assigns the contents of other.
  • (2) Inserts value into the associated stream, then inserts the delimiter, if one was specified at construction time.

If out_stream is a pointer to the associated std::basic_ostream and delim is the delimiter specified at the construction of this object, then the effect is equivalent to:

*out_stream << value;
if (delim != 0)
    *out_stream << delim;
return *this;

That’s the whole vibe check: shove value into *out_stream, then if delim != 0, shove delim too, and hand back *this πŸ’–.

πŸŽ€ Parameters πŸŽ€

  • value β€” the object to insert

🌈 Return value 🌈

*this β€” and that’s on periodt ✨.

πŸ’œ Notes πŸ’œ

  • T can be any class with a user-defined operator<<.
  • Prior to C++20, the existence of the copy assignment operator relied on the deprecated implicit generation.
heads up bestie: β€œdeprecated” is right there in the original, so don’t come for me β€” that’s a real caveat 🫢.

πŸ”₯ Example πŸ”₯

// Run this code

#include <iostream>
#include <iterator>

int main()
{
    std::ostream_iterator<int> i1(std::cout, ", ");
    *i1++ = 1; // usual form, used by standard algorithms
    *++i1 = 2;
    i1 = 3; // neither * nor ++ are necessary
    std::ostream_iterator<double> i2(std::cout);
    i2 = 3.14;
    std::cout << '\n';
}

🌟 Output 🌟

1, 2, 3, 3.14

okay that’s the whole assignment-operator saga, bestie 🫢 β€” sourced from http://cppreference.com, date/version 2024.06.10, and the page name is std::ostrea...::operator=(3). stay slay, and may your delimiters always pass the vibe check πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from