29 Input/output library [input.output]

29.10 Synchronized output streams [syncstream]

29.10.3 Class template basic_­osyncstream [syncstream.osyncstream]

29.10.3.3 Member functions [syncstream.osyncstream.members]

void emit();
Effects: Calls sb.emit().
If that call returns false, calls setstate(ios_­base​::​badbit).
[Example
:
A flush on a basic_­osyncstream does not flush immediately:
{
  osyncstream bout(cout);
  bout << "Hello," << '\n';     // no flush
  bout.emit();                  // characters transferred; cout not flushed
  bout << "World!" << endl;     // flush noted; cout not flushed
  bout.emit();                  // characters transferred; cout flushed
  bout << "Greetings." << '\n'; // no flush
}   // characters transferred; cout not flushed
— end example
]
[Example
:
The function emit() can be used to handle exceptions from operations on the underlying stream.
{
  osyncstream bout(cout);
  bout << "Hello, " << "World!" << '\n';
  try {
    bout.emit();
  } catch (...) {
    // handle exception
  }
}
— end example
]
streambuf_type* get_wrapped() const noexcept;
Returns: sb.get_­wrapped().
[Example
:
Obtaining the wrapped stream buffer with get_­wrapped() allows wrapping it again with an osyncstream.
For example,
{
  osyncstream bout1(cout);
  bout1 << "Hello, ";
  {
    osyncstream(bout1.get_wrapped()) << "Goodbye, " << "Planet!" << '\n';
  }
  bout1 << "World!" << '\n';
}
produces the uninterleaved output
Goodbye, Planet!
Hello, World!
— end example
]