- thread[meta header]
- std[meta namespace]
- jthread[meta class]
- function[meta id-type]
- cpp20[meta cpp]
[[nodiscard]] bool joinable() const noexcept; // (1) C++20
bool joinable() const noexcept; // (1) C++26
jthread
オブジェクトがスレッドと関連付けられているか否か取得する。
return get_id() != id();
- get_id()[link get_id.md]
- id[link /reference/thread/thread/id.md]
送出しない。
#include <cassert>
#include <thread>
int main()
{
std::jthread t([]{ /*...*/ });
assert(t.joinable());
t.join();
assert(!t.joinable());
}
- joinable()[color ff0000]
- C++20
- Clang:
- GCC: 10.2.0 [mark verified]
- Visual C++: ??
- P2422R1 Remove
nodiscard
annotations from the standard library specification- C++26で
[[nodiscard]]
指定が削除された
- C++26で