Skip to content

Latest commit

 

History

History
62 lines (48 loc) · 2.11 KB

emit_on_flush.md

File metadata and controls

62 lines (48 loc) · 2.11 KB

emit_on_flush

  • ostream[meta header]
  • std[meta namespace]
  • function template[meta id-type]
  • cpp20[meta cpp]
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 となっているため、
                      // ここで文字が転送される。
}
  • emit_on_flush[color ff0000]

出力

Hello, World!

バージョン

言語

  • C++20

参照