explicit basic_syncbuf(streambuf_type* obuf = nullptr)
: basic_syncbuf(obuf, Allocator()) { } // (1)
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator); // (2)
basic_syncbuf(basic_syncbuf&& other); // (3)
概要
- (1) : デフォルトコンストラクタ。ラップする
std::basic_streambufへのポインタを受け取る。 - (2) : ラップする
std::basic_streambufへのポインタ、アロケータを受け取る。 - (3) : ムーブコンストラクタ。
ただし、これらは通常std::basic_osyncstreamから呼ばれる。
効果
- (1), (2) : 同期時排出ポリシー(
sync()が呼ばれたときemit()を呼び出すかどうか)をfalseに設定し、std::basic_syncbufオブジェクトを作成し、ラップされたストリームバッファをobufに設定する。obufが、関連する出力の最終的な宛先になる。 - (3) : 他のオブジェクトからムーブコンストラクトする。
例外
- (1), (2) : ミューテックスの構築から
std::system_error、またはメモリ割り当てによってstd::bad_alloc例外がスローされる可能性がある。
事後条件
- (1), (2) :
get_wrapped() == obufとget_allocator() == allocatorがtrueとなる。 - (3) :
this->get_wrapped()によって返される値は、このコンストラクタを呼び出す前にother.get_wrapped()によって返される値である。 このコンストラクタを呼び出す前にotherに格納された出力は、*thisに格納される。other.rdbuf()->pbase() == other.rdbuf()->pptr()とother.get_wrapped() == nullptrはtrueである。
備考
- (1), (2) : アロケータのコピーは、関連する出力を保持する内部バッファにメモリを割り当てるために使用される。
- (3) : このコンストラクタは、
otherをそのラップされたストリームバッファから切り離し、otherの破棄によって出力がされないようにする。
例
#include <iostream>
#include <syncstream>
int main()
{
std::osyncstream bout{std::cout}; // 通常 std::basic_osyncstream から呼ばれる。
bout << "Hello, World!";
}
出力
Hello, World!
バージョン
言語
- C++20
処理系
- Clang: ??
- GCC: 11.1 ✅
- Visual C++: 2019 update 10 ✅