From cppreference.com
This header is part of the
library.
Classes
(C++20)
an interface for querying if a
cancellation request has been made
(class)
(C++20)
class representing a request to stop one or more
s
(class)
(C++20)
an interface for registering callbacks on
cancellation
(class template)
(C++26)
provides a stop token interface that a stop is never possible nor requested
(class)
(C++26)
a stop token that references stop state of its associated std::inplace_stop_source object
(class)
(C++26)
a stoppable-source that is the sole owner of the stop state
(class)
(C++26)
a stop callback for std::inplace_stop_token
(class template)
Alias templates
(C++26)
obtains the callback type for a given stop token type
(alias template)
Concepts
(C++26)
specifies the basic interface of stop tokens which allows queries for stop requests and whether the stop request is possible
(concept)
(C++26)
specifies a stop token that does not allow stopping
(concept)
Tags
(C++20)
a tag used for stop_source to indicate no associated stop-state upon construction
(tag)
Synopsis
namespacestd{// stop token conceptstemplate<classCallbackFn,classToken,classInit=CallbackFn>concept/*stoppable-callback-for*/=/* see description */;// exposition onlytemplate<classToken>conceptstoppable_token=/* see description */;template<classToken>conceptunstoppable_token=/* see description */;template<classSource>concept/*stoppable-source*/=/* see description */;// exposition only// class stop_tokenclassstop_token;// class stop_sourceclassstop_source;// no-shared-stop-state indicatorstructnostopstate_t{explicitnostopstate_t()=default;};inlineconstexprnostopstate_tnostopstate{};// class template stop_callbacktemplate<classCallback>classstop_callback;// class never_stop_tokenclassnever_stop_token;// class inplace_stop_tokenclassinplace_stop_token;// class inplace_stop_sourceclassinplace_stop_source;// class template inplace_stop_callbacktemplate<classCallbackFn>classinplace_stop_callback;template<classT,classCallbackFn>usingstop_callback_for_t=T::templatecallback_type<CallbackFn>;}Stop token concepts
namespacestd{template<classCallbackFn,classToken,classInit=CallbackFn>concept/*stoppable-callback-for*/=// exposition onlyinvocable<CallbackFn>&&constructible_from<CallbackFn,Init>&&requires{typenamestop_callback_for_t<Token,CallbackFn>;}&&constructible_from<stop_callback_for_t<Token,CallbackFn>,constToken&,Init>;template<template<class>class>struct/*check-type-alias-exists*/;// exposition onlytemplate<classToken>conceptstoppable_token=requires(constTokentok){typename/*check-type-alias-exists*/<Token::templatecallback_type>;{tok.stop_requested()}noexcept->same_as<bool>;{tok.stop_possible()}noexcept->same_as<bool>;{Token(tok)}noexcept;// see implicit expression variations}&©able<Token>&&equality_comparable<Token>;template<classToken>conceptunstoppable_token=stoppable_token<Token>&&requires(constTokentok){requiresbool_constant<(!tok.stop_possible())>::value;};template<classSource>concept/*stoppable-source*/=// exposition onlyrequires(Source&src,constSourcecsrc){{csrc.get_token()}->stoppable_token;{csrc.stop_possible()}noexcept->same_as<bool>;{csrc.stop_requested()}noexcept->same_as<bool>;{src.request_stop()}->same_as<bool>;};}Class
namespacestd{classstop_token{public:template<classCallbackFn>usingcallback_type=stop_callback<CallbackFn>;// constructors, copy, and assignmentstop_token()noexcept=default;// member functionsvoidswap(stop_token&)noexcept;// stop handlingboolstop_requested()constnoexcept;boolstop_possible()constnoexcept;friendbooloperator==(conststop_token&lhs,conststop_token&rhs)noexcept;friendvoidswap(stop_token&lhs,stop_token&rhs)noexcept;private:shared_ptr</*unspecified*/>stop_state_;// exposition only};}Class
namespacestd{classstop_source{public:// constructors, copy, and assignmentstop_source();explicitstop_source(nostopstate_t)noexcept{}// member functionsvoidswap(stop_source&)noexcept;// stop handlingstop_tokenget_token()constnoexcept;boolstop_possible()constnoexcept;boolstop_requested()constnoexcept;boolrequest_stop()noexcept;friendbooloperator==(conststop_source&lhs,conststop_source&rhs)noexcept;friendvoidswap(stop_source&lhs,stop_source&rhs)noexcept;private:shared_ptr</*unspecified*/>stop_state_;// exposition only};}Class template
namespacestd{template<classCallbackFn>classstop_callback{public:usingcallback_type=CallbackFn;// constructors and destructortemplate<classInit>explicitstop_callback(conststop_token&st,Init&&init)noexcept(is_nothrow_constructible_v<CallbackFn,Init>);template<classInit>explicitstop_callback(stop_token&&st,Init&&init)noexcept(is_nothrow_constructible_v<CallbackFn,Init>);~stop_callback();stop_callback(conststop_callback&)=delete;stop_callback(stop_callback&&)=delete;stop_callback&operator=(conststop_callback&)=delete;stop_callback&operator=(stop_callback&&)=delete;private:CallbackFncallback_fn_;// exposition only};template<classCallbackFn>stop_callback(stop_token,CallbackFn)->stop_callback<CallbackFn>;}Class template std::never_stop_token
namespacestd{classnever_stop_token{struct/*callback-type*/{// exposition onlyexplicit/*callback-type*/(never_stop_token,auto&&)noexcept{}};public:template<class>usingcallback_type=/*callback-type*/;staticconstexprboolstop_requested()noexcept{returnfalse;}staticconstexprboolstop_posible()noexcept{returnfalse;}booloperator==(constnever_stop_token&)const=default;};}Class template std::inplace_stop_token
namespacestd{classinplace_stop_token{public:template<classCallbackFn>usingcallback_type=inplace_stop_callback<CallbackFn>;inplace_stop_token()=default;booloperator==(constinplace_stop_token&)const=default;// member functionsboolstop_requested()constnoexcept;boolstop_possible()constnoexcept;voidswap(inplace_stop_token&)noexcept;private:constinplace_stop_source*stop_source_=nullptr;// exposition only};}Class template std::inplace_stop_source
namespacestd{classinplace_stop_source{// constructors, assignments, and destructorconstexprinplace_stop_source()noexcept;inplace_stop_source(inplace_stop_source&&)=delete;inplace_stop_source(constinplace_stop_source&)=delete;inplace_stop_source&operator=(inplace_stop_source&&)=delete;inplace_stop_source&operator=(constinplace_stop_source&)=delete;~inplace_stop_source();// stop handlingconstexprinplace_stop_tokenget_token()constnoexcept;staticconstexprboolstop_possible()noexcept{returntrue;}boolstop_requested()constnoexcept;boolrequest_stop()noexcept;};}Class template std::inplace_stop_callback
namespacestd{template<classCallbackFn>classinplace_stop_callback{public:usingcallback_type=CallbackFn;// constructors and destructortemplate<classInit>explicitinplace_stop_callback(inplace_stop_tokenst,Init&&init)noexcept(is_nothrow_constructible_v<CallbackFn,Init>);~inplace_stop_callback();inplace_stop_callback(constinplace_stop_callback&)=delete;inplace_stop_callback(inplace_stop_callback&&)=delete;inplace_stop_callback&operator=(constinplace_stop_callback&)=delete;inplace_stop_callback&operator=(inplace_stop_callback&&)=delete;private:CallbackFncallback_fn_;// exposition only};template<classCallbackFn>inplace_stop_callback(inplace_stop_token,CallbackFn)->inplace_stop_callback<CallbackFn>;}