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

履歴 編集

function
<syncstream>

std::basic_osyncstream::コンストラクタ(C++20)

basic_osyncstream(streambuf_type* buf, const Allocator& allocator);              // (1)

explicit basic_osyncstream(streambuf_type* obuf)
  : basic_osyncstream(obuf, Allocator()) {}                                      // (2)

basic_osyncstream(basic_ostream<charT, traits>& os, const Allocator& allocator)
  : basic_osyncstream(os.rdbuf(), allocator) {}                                  // (3)

explicit basic_osyncstream(basic_ostream<charT, traits>& os)
  : basic_osyncstream(os, Allocator()) {}                                        // (4)

basic_osyncstream(basic_osyncstream&& other) noexcept;                           // (5)

概要

  • (1)〜(4) : ラップするストリーム、アロケータ(もしあれば)を受け取るコンストラクタ。
  • (5) : ムーブコンストラクタ。

効果

  • (1) : 提供されるストリームバッファ(buf)、アロケータ(allocator)を使用してプライベートメンバのstd::basic_syncbufを初期化し、そのポインタを用いて基底クラスであるstd::basic_ostreamを初期化する。
  • (2)(3) : (1)に委譲。
  • (4) : (3)に委譲。
  • (5) : 対応するotherのサブオブジェクトから基底クラスとプライベートメンバのstd::basic_syncbufをムーブ構築し、基底クラスの初期化を完了するためにstd::basic_ostream<charT、traits>::set_rdbuf(addressof(sb))を呼び出す。

事後条件

  • (1)〜(4) : get_wrapped() == buftrueである。
  • (5) : get_wrapped()によって返される値は、このコンストラクタを呼び出す前にos.get_wrapped()によって返される値である。また、nullptr == other.get_wrapped()trueである。

#include <iostream>
#include <syncstream>

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

出力

Hello, World!

バージョン

言語

  • C++20

処理系

参照