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

履歴 編集

function
<syncstream>

std::basic_syncbuf::swap(C++20)

void swap(basic_syncbuf& other) noexcept;

概要

他のbasic_syncbufオブジェクトと、データを交換する。

事前条件

allocator_traits<Allocator>::propagate_on_container_swap::valuetrueであるか、または this->get_allocator() == other.get_allocator()trueである。

効果

*thisotherの状態を交換する。

戻り値

なし

例外

投げない

#include <iostream>
#include <syncstream>

int main()
{
  std::osyncstream aout{std::cout};
  aout << "Hello, ";

  std::osyncstream bout;
  bout << "World!";

  aout.rdbuf()->swap(*bout.rdbuf());

  bout.emit(); // "Hello, " が転送される
  aout.emit(); // "World!" が転送される
}

出力

Hello, World!

バージョン

言語

  • C++20

処理系

参照