- stop_token[meta header]
- std[meta namespace]
- stop_source[meta class]
- function[meta id-type]
- cpp20[meta cpp]
stop_source& operator=(const stop_source& r) noexcept; // (1)
stop_source& operator=(stop_source&& r) noexcept; // (2)- (1) : コピー代入演算子。
- (2) : ムーブ代入演算子。
- (1) :
stop_source(r).swap(*this)。これによって*this==rとなる。 - (2) :
stop_source(std::move(r)).swap(*this)。これによって、r.stop_possible()==trueとなる。
*this
投げない。
#include <cassert>
#include <stop_token>
int main()
{
std::stop_source ss1;
std::stop_source ss2(std::nostopstate);
std::stop_source ss3(std::nostopstate);
assert(ss1.stop_possible() == true);
assert(ss2.stop_possible() == false);
assert(ss1.stop_requested() == false);
assert(ss2.stop_requested() == false);
// (1) コピー代入演算子
ss2 = ss1;
assert(ss2 == ss1);
assert(ss1.stop_possible() == true);
assert(ss2.stop_possible() == true);
// (2) ムーブ代入演算子
ss3 = std::move(ss1);
assert(ss1.stop_possible() == false);
assert(ss3.stop_possible() == true);
ss2.request_stop();
assert(ss1.stop_requested() == false);
assert(ss2.stop_requested() == true);
assert(ss3.stop_requested() == true);
}- std::move[link /reference/utility/move.md]
- stop_source[link ../stop_source.md]
- nostopstate[link ../nostopstate.md]
- stop_requested()[link stop_requested.md]
- stop_possible()[link stop_possible.md]
- C++20
- GCC: ??
- Clang: ??
- ICC: ??
- Visual C++: ??