[[nodiscard]]
stop_token get_token() const noexcept; // (1) C++20
stop_token get_token() const noexcept; // (1) C++26
概要
自身と停止状態を共有するstop_token
を構築して返す。
戻り値
stop_possible() == false
のときは、デフォルト構築したstop_token
を返す。それ以外の場合は、自身と停止状態を共有するstop_token
を構築して返す。
例外
投げない。
例
#include <cassert>
#include <stop_token>
int main()
{
std::stop_source ss1;
std::stop_source ss2(std::nostopstate);
std::stop_token st1 = ss1.get_token();
std::stop_token st2 = ss2.get_token();
assert(st1.stop_possible() == true);
assert(st2.stop_possible() == false);
}
xxxxxxxxxx
#include <cassert>
#include <stop_token>
int main()
{
std::stop_source ss1;
std::stop_source ss2(std::nostopstate);
std::stop_token st1 = ss1.get_token();
std::stop_token st2 = ss2.get_token();
assert(st1.stop_possible() == true);
assert(st2.stop_possible() == false);
}
出力
バージョン
言語
- C++20
処理系
- Clang: ??
- GCC: ??
- ICC: ??
- Visual C++: ??
参照
- P2422R1 Remove
nodiscard
annotations from the standard library specification- C++26で
[[nodiscard]]
指定が削除された
- C++26で