最終更新日時(UTC):
が更新

履歴 編集

function template
<ostream>

std::emit_on_flush(C++20)

namespace std {
  template<class charT, class traits>
  basic_ostream<charT, traits>& emit_on_flush(basic_ostream<charT, traits>& os);
}

概要

このマニピュレータは、実際にはstd::basic_osyncstreamに対して使用されることが期待される。std::basic_osyncstreamのベースとなるstd::basic_syncbufの同期時排出ポリシーをtrueに変更する。つまり、std::basic_osyncstreamのオブジェクトにflush()が呼ばれた際、文字が転送されるようになる。
また、対になるマニピュレータとして、noemit_on_flushが存在する。

効果

os.rdbuf()std::basic_syncbuf<charT、traits、Allocator>*である場合、これをbufとすると、buf->set_emit_on_sync(true)を呼び出す。
それ以外の場合、このマニピュレータは効果がない。

戻り値

os

備考

本関数は、直接呼ぶのではなく、マニピュレータ関数へのポインタを引数に取る出力演算子(operator<<、挿入演算子、インサータとも呼ばれる)を通じて呼び出されるのが一般的である。

#include <iostream>
#include <syncstream>

int main()
{
  std::osyncstream bout{std::cout};
  bout << "Hello, World!";

  bout << std::emit_on_flush;

  bout << std::flush; // 通常はここで保留中の文字は転送されないが、
                      // emit_on_flush を呼び出し、同期時排出ポリシーが true となっているため、
                      // ここで文字が転送される。
}

出力

Hello, World!

バージョン

言語

  • C++20

参照