basic_filebuf& operator=(const basic_filebuf&) = delete; // (1) C++11
basic_filebuf& operator=(basic_filebuf&& rhs); // (2) C++11
概要
- (1) : コピー代入。この演算子は
delete定義されており、basic_filebufオブジェクトはコピーできない - (2) : ムーブ代入。
rhsが管理していたファイルの所有権を*thisに移動する
効果
- (2) :
close()を呼び出したのち、rhsからムーブ代入する
事後条件
戻り値
- (2) :
*this
例
#include <iostream>
#include <fstream>
#include <utility>
int main()
{
{
std::filebuf out;
out.open("test.txt", std::ios_base::out);
out.sputn("Hello", 5);
}
std::filebuf a;
a.open("test.txt", std::ios_base::in);
std::filebuf b;
b = std::move(a); // aが開いていたファイルをbに移動する
std::cout << std::boolalpha
<< a.is_open() << ' '
<< b.is_open() << std::endl;
std::cout << static_cast<char>(b.sbumpc()) << std::endl;
}
出力
false true
H
バージョン
言語
- C++11