syncstream[meta header]
std[meta namespace]
class template[meta id-type]
cpp20[meta cpp]
namespace std {
template <class charT , class traits , class Allocator >
class basic_syncbuf : public basic_streambuf <charT, traits> { ... };
using syncbuf = basic_syncbuf<char >;
using wsyncbuf = basic_syncbuf<wchar_t >;
}
basic_streambuf[link ../streambuf/basic_streambuf.md]
クラステンプレートbasic_syncbuf
は、書き込まれた文字データをオブジェクトのアロケータを使って割り当てられた内部バッファに格納する。
格納された文字データは、emit()
が呼び出されたとき、またはbasic_syncbuf
オブジェクトが破棄されたときに、ラップされたストリームバッファオブジェクトに転送される。
このような転送は、同じラップストリームバッファオブジェクトを持つ他のbasic_syncbuf
オブジェクトによる転送に関してアトミックである。
エイリアス
説明
対応バージョン
syncbuf
basic_syncbuf<char>
C++20
wsyncbuf
basic_syncbuf<wchar_t>
C++20
基底クラスである basic_streambuf
も参照のこと。
名前
説明
対応バージョン
operator=
代入演算子
C++20
swap
他のbasic_syncbuf
オブジェクトと状態を交換する
C++20
プロテクテッドなオーバーライドされた仮想メンバ関数
名前
説明
対応バージョン
sync
フラッシュが保留されていることを記録し、 現在の同期時排出ポリシーに応じてemit()
を呼び出す(デフォルトでは呼び出さない)
C++20
名前
説明
対応バージョン
char_type
charT
C++20
traits_type
Traits
Traits::char_type
がCharT
でない場合、プログラムは不適格である
C++20
int_type
Traits::int_type
C++20
pos_type
Traits::pos_type
C++20
off_type
Traits::off_type
C++20
allocator_type
Allocator
C++20
streambuf_type
std::basic_streambuf<CharT, Traits>
C++20
名前
説明
対応バージョン
swap
2つのbasic_syncbuf
オブジェクトを入れ替える
C++20
#include < iostream>
#include < syncstream>
#include < thread>
void thread1 ()
{
{
// std::basic_syncbuf は通常、直接でなく、
// 対応するストリーム std::osyncstream を通してのみアクセスされる
std::osyncstream bout{std::cout};
bout << " Hello, " ;
bout << " World!" ;
bout << std::endl; // フラッシュがノートされる
bout << " and more!\n " ;
} // 文字が転送され、cout はフラッシュする
}
void thread2 ()
{
// 同じバッファに行われる出力は、異なる std::basic_osyncstream(std::basic_syncbuf) の
// インスタンスからでも、アトミックに出力されることが保証される
std::osyncstream (std::cout) << " Goodbye, " << " Planet!" << ' \n ' ;
}
int main ()
{
std::thread th1 (thread1);
std::thread th2 (thread2);
th1.join ();
th2.join ();
}
osyncstream[color ff0000]
thread1 の処理が先行した場合。ただし、各出力は連続したシーケンスとなるように、アトミックに行われることが保証される。
Hello, World!
and more!
Goodbye, Planet!