- thread[meta header]
- std[meta namespace]
- jthread[meta class]
- function[meta id-type]
- cpp20[meta cpp]
jthread& operator=(const jthread&) = delete; // (1) C++20
jthread& operator=(jthread&& x) noexcept; // (2) C++20jthreadオブジェクトの代入。
- (1) : コピー代入。コピー不可
- (2) : ムーブ代入。ムーブ不可
joinable()がtrueを返す場合、request_stop()とjoin()を呼び出すxの状態を*thisに代入し、xをデフォルト構築された状態に設定する
x.get_id()==id()であることget_id()の呼び出しでは、代入前のx.get_id()が返されるようになること- メンバ変数として保持している
std::stop_source型オブジェクトssourceは、代入前のx.ssourceの値を持ち、x.ssource.stop_possible()はfalseとなること
*thisを返す。
#include <thread>
#include <cassert>
int main()
{
std::jthread t1([]{ /*...*/ });
std::jthread t2;
assert(t1.joinable() && !t2.joinable());
// t1からt2へムーブ代入
t2 = std::move(t1);
assert(!t1.joinable() && t2.joinable());
t2.join();
}- t2 = std::move(t1);[color ff0000]
- joinable()[link joinable.md]
- C++20
- Clang:
- GCC: 10.2.0
- Visual C++: ??