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

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

πŸ’– std::experi...::operator=(3) πŸ’–

okay so bestie, welcome to std::experi...::operator=(3) from the C++ Standard Libary manual β€” yes, that spelling is exactly what the page says, no cap. This one is all about the assignment operator for std::experimental::ostream_joiner, and it's giving "write stuff to a stream with a delimiter" energy. let's go πŸ¦‹


🌸 NAME 🌸

  • std::experimental::ostream_joiner::operator= β€” std::experimental::ostream_joiner::operator=. yes bestie, it's listed twice on the page, and we're keeping both. πŸ’…

✨ Synopsis ✨

three overloads, bestie. keep the code exact, no renaming, no merging:

template< class T >                                 (1) (library fundamentals TS v2)
ostream_joiner& operator=( const T& value );

ostream_joiner& operator=( const ostream_joiner& other ) = default;    (2) (library fundamentals TS v2) (implicitly declared)

ostream_joiner& operator=( ostream_joiner&& other ) = default;        (3) (library fundamentals TS v2) (implicitly declared)

here's the tea on each one πŸ«–

  1. First, if the private "first element" flag is false, insert the delimiter delim into the output stream os associated with this iterator as if by os << delim;. Then, unconditionally sets the "first element" flag to false, and insert value into the output stream as if by os << value;. Let out_stream, delim, and first_element denote the private stream pointer, delimiter, and "first element" flag members respectively. Then this function is equivalent to:
if (!first_element)
    *out_stream << delim;
first_element = false;
*out_stream << value;
return *this;

2,3) Implicitly declared copy/move assignment operator that copy/move assigns the private stream pointer, delimiter, and "first element" flag members. slay, that's literally it. πŸ’…


🫢 Parameters 🫢

  • value β€” the object to to be written to the stream (yes, the page says "to to" β€” keeping it exactly, bestie πŸ’€)
  • other β€” the ostream_joiner object to be assigned to this object

πŸ’… Return value πŸ’…

*this. β€” that's the return value, periodt. πŸ’–


πŸŽ€ Example πŸŽ€

run this code:

// Run this code

#include <experimental/iterator>
#include <iostream>

int main()
{
    auto joiner = std::experimental::make_ostream_joiner(std::cout, ", ");
    joiner = "First";
    joiner = "do no harm.";  // prefixes with the delimiter
}

🌈 Output 🌈

First, do no harm.

okay that's the whole page, bestie. source: http://cppreference.com, version/date: 2024.06.10, page: std::experi...::operator=(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from