Namespaces
Variants

std::basic_osyncstream<CharT,Traits,Allocator>:: operator=

From cppreference.net
basic_osyncstream & operator = ( std:: basic_osyncstream && other ) ;
(C++20 起)

移动赋值一个同步输出流:

将包装的 std::basic_syncbuf other 的对应成员移动赋值(在此移动赋值后, other. get_wrapped ( ) 将返回空指针,且 other 的析构不会产生输出;所有待处理的缓冲输出将被发送)并 移动赋值 基类 std::basic_ostream (这会交换 * this other 之间除 rdbuf 外的所有流状态变量)

目录

参数

其他 - 待移动的另一个同步输出流

返回值

* 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() 以将其内部数据传输至最终目标
(公开成员函数)