[[nodiscard]]
bool stop_requested() const noexcept; // (1) C++20
bool stop_requested() const noexcept; // (1) C++26
概要
停止要求が作成されたかどうかを返す。
戻り値
自身が停止状態を所有していて、その停止状態が停止要求を受け取っている場合はtrue
を返す。それ以外の場合はfalse
を返す。
例外
投げない。
例
#include <cassert>
#include <stop_token>
int main()
{
std::stop_source ss1;
std::stop_source ss2(std::nostopstate);
assert(ss1.stop_requested() == false);
assert(ss2.stop_requested() == false);
ss1.request_stop();
ss2.request_stop();
assert(ss1.stop_requested() == true);
assert(ss2.stop_requested() == false);
}
18
#include <cassert>
#include <stop_token>
int main()
{
std::stop_source ss1;
std::stop_source ss2(std::nostopstate);
assert(ss1.stop_requested() == false);
assert(ss2.stop_requested() == false);
ss1.request_stop();
ss2.request_stop();
assert(ss1.stop_requested() == true);
assert(ss2.stop_requested() == false);
}
出力
バージョン
言語
- C++20
処理系
- Clang: ??
- GCC: ??
- ICC: ??
- Visual C++: ??
参照
- P2422R1 Remove
nodiscard
annotations from the standard library specification- C++26で
[[nodiscard]]
指定が削除された
- C++26で