std::emit_on_flush / std::noemit_on_flush
std::emit_on_flush / std::noemit_on_flush (flush 시 emit 조작자)
std::basic_syncbuf 버퍼가 flush될 때 emit(즉 기반 스트림 버퍼로 데이터 전송)할지 여부를 전환하는 조작자들이에요. C++20부터 있어요.
출처: cppreference
본문
<ostream> 헤더에 정의돼 있어요.
// (1) C++20
template< class CharT, class Traits >
std::basic_ostream<CharT, Traits>& emit_on_flush( std::basic_ostream<CharT, Traits>& os );
// (2) C++20
template< class CharT, class Traits >
std::basic_ostream<CharT, Traits>& noemit_on_flush( std::basic_ostream<CharT, Traits>& os );
os.rdbuf()가 실제로 std::basic_syncbuf<CharT, Traits, Allocator> 버퍼 buf를 가리키면, flush될 때 emit(즉 데이터를 기반 스트림 버퍼로 전송)할지 여부를 전환해요.
-
buf.set_emit_on_sync(true)를 호출해요.
-
buf.set_emit_on_sync(false)를 호출해요.
그 외의 경우 이 조작자들은 효과가 없어요. 출력 전용 I/O 조작자라 out << std::emit_on_flush처럼 쓸 수 있어요.
예제
#include <syncstream>
#include <iostream>
int main()
{
{
std::osyncstream out(std::cout);
out << std::noemit_on_flush << "모아둠";
// 블록 종료 시 전체가 한 번에 전송됨
}
}