std::basic_osyncstream<CharT,Traits,Allocator>::operator=
来自cppreference.com
<tbody>
</tbody>
basic_osyncstream& operator=( std::basic_osyncstream&& other ); |
(C++20 起) | |
移动赋值同步输出流。
从 other 的对应成员移动赋值被包装的 std::basic_syncbuf(此移动赋值后,other.get_wrapped() 返回空指针,而 other 的析构不产生输出;放出任何待决的缓冲输出)并移动赋值基类 std::basic_ostream(这会在 *this 和 other 间交换除了 rdbuf 之外的所有流状态变量)。
参数
| other | - | 要移动的另一同步输出流 |
返回值
*this
示例
运行此代码
#include <iomanip>
#include <iostream>
#include <sstream>
#include <syncstream>
#include <utility>
int main()
{
std::osyncstream out(std::cout);
out << "test\n";
std::ostringstream str_out;
std::osyncstream{str_out} = std::move(out); // 注意 out 于此处发出
std::cout << "str_out = " << std::quoted(str_out.view()) << '\n';
}
输出:
test
str_out = ""
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| 缺陷报告 | 应用于 | 出版时的行为 | 正确行为 |
|---|---|---|---|
| LWG 3867 | C++20 | 移动赋值运算符是 noexcept 的,但是 std::basic_syncbuf 的移动赋值运算符不是
|
移除 noexcept
|
参阅
构造 basic_osyncstream 对象 (公开成员函数) | |
销毁 basic_osyncstream 并发出它的内部缓冲区 (公开成员函数) | |
调用底层 basic_syncbuf 上的 emit() 以传输它的内部数据到最终目标 (公开成员函数) |