std::experi...::operator=(3)
π 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 π«
- First, if the private "first element" flag is
false, insert the delimiterdeliminto the output streamosassociated with this iterator as if byos << delim;. Then, unconditionally sets the "first element" flag tofalse, and insertvalueinto the output stream as if byos << value;. Letout_stream,delim, andfirst_elementdenote 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β theostream_joinerobject 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
- 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