future& operator=(const future& rhs) = delete; // (1)
future& operator=(future&& rhs) noexcept; // (2)
概要
- (1) : コピー代入。コピー不可。
- (2) : ムーブ代入。
効果
- (2) :
addressof(rhs) == this(自己代入)の場合、効果はない。それ以外の場合、共有状態を解放し、rhsの共有状態を含むコンテンツを*thisにムーブ代入する。
戻り値
- (2) :
*this
事後条件
- (2) :
valid()の戻り値が、この関数を呼び出す前のrhs.valid()と等価になること。addressof(rhs) != this(自己代入でない)の場合、rhs.valid() == falseになること。
例外
- (2) : 投げない
例
#include <future>
int main()
{
std::promise<int> p;
std::future<int> f;
f = p.get_future();
}
出力
バージョン
言語
- C++11
処理系
- Clang: ??
- GCC: 4.7.0 ✅
- Visual C++: 2012 ✅
参照
- LWG Issue 3795. Self-move-assignment of
std::futureandstd::shared_futurehave unimplementable postconditions- C++23で、自己代入(
addressof(rhs) == this)の場合は効果がないことが効果に明記され、事後条件のrhs.valid() == falseが「自己代入でない場合」に条件付けられた
- C++23で、自己代入(