void swap(basic_syncbuf& other) noexcept;
概要
他のbasic_syncbufオブジェクトと、データを交換する。
事前条件
allocator_traits<Allocator>::propagate_on_container_swap::valueがtrueであるか、または
this->get_allocator() == other.get_allocator()がtrueである。
効果
*thisとotherの状態を交換する。
戻り値
なし
例外
投げない
例
#include <iostream>
#include <syncstream>
int main()
{
std::osyncstream aout{std::cout};
aout << "Hello, ";
std::osyncstream bout{std::cout};
bout << "World!";
aout.rdbuf()->swap(*bout.rdbuf());
bout.emit(); // "Hello, " が転送される
aout.emit(); // "World!" が転送される
}
出力
Hello, World!
バージョン
言語
- C++20
処理系
- Clang: ??
- GCC: 11.1 ✅
- Visual C++: 2019 update 10 ✅