std::basic_ostream<CharT,Traits>::operator=
From cppreference.com
< cpp | io | basic_ostream
| protected: basic_ostream& operator=( const basic_ostream& rhs ) = delete; |
(1) | |
| protected: basic_ostream& operator=( basic_ostream&& rhs ); |
(2) | (C++11以降) |
1) コピー代入演算子は保護されており、削除されています。出力ストリームはCopyAssignableではありません。
2) ムーブ代入演算子は、rdbuf() を除く基底クラスのすべてのデータメンバーを、rhs と交換します。これは、swap(*rhs) を呼び出すのと同様です。このムーブ代入演算子は保護されており、関連するストリームバッファを正しくムーブ代入する方法を知っている派生ムーブ可能な出力ストリームクラスである std::basic_ofstream および std::basic_ostringstream のムーブ代入演算子からのみ呼び出されます。
[編集] パラメータ
| rhs | - | *this に代入する `basic_ostream` オブジェクト。 |
[編集] 例
このコードを実行
#include <iostream> #include <sstream> #include <utility> int main() { std::ostringstream s; // std::cout = s; // ERROR: copy assignment operator is deleted // std::cout = std::move(s); // ERROR: move assignment operator is protected s = std::move(std::ostringstream() << 42); // OK, moved through derived std::cout << s.str() << '\n'; }
出力
42
[編集] 不具合報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 2067 | C++11 | 1. オーバーロード (1) のパラメータ型は basic_ostream& でした。2. オーバーロード (2) のパラメータ型は const basic_ostream&& でした。 |
1. const を追加しました。 2. const を削除しました。 |