27 Input/output library [input.output]

27.10 Synchronized output streams [syncstream]

27.10.3 Class template basic_­osyncstream [syncstream.osyncstream]

27.10.3.4 Member functions [syncstream.osyncstream.members]

void emit();
Effects: Calls sb.emit().
If that call returns false, calls setstate(ios::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
]