32 Concurrency support library [thread] (original) (raw)

32.3 Stop tokens [thread.stoptoken]

32.3.6 Class template stop_callback [stopcallback]


32.3.6.1 General [stopcallback.general]

32.3.6.2 Constructors and destructor [stopcallback.cons]


32.3.6.1 General [stopcallback.general]

namespace std { template<class CallbackFn> class stop_callback { public: using callback_type = CallbackFn;template<class Initializer> explicit stop_callback(const stop_token& st, Initializer&& init) noexcept(is_nothrow_constructible_v<CallbackFn, Initializer>);template<class Initializer> explicit stop_callback(stop_token&& st, Initializer&& init) noexcept(is_nothrow_constructible_v<CallbackFn, Initializer>);~stop_callback(); stop_callback(const stop_callback&) = delete; stop_callback(stop_callback&&) = delete; stop_callback& operator=(const stop_callback&) = delete; stop_callback& operator=(stop_callback&&) = delete;private: CallbackFn callback-fn; };template<class CallbackFn> stop_callback(stop_token, CallbackFn) -> stop_callback<CallbackFn>;}

Mandates: stop_callback is instantiated with an argument for the template parameter CallbackFnthat satisfies both invocableand destructible.

32.3.6.2 Constructors and destructor [stopcallback.cons]

template<class Initializer> explicit stop_callback(const stop_token& st, Initializer&& init) noexcept(is_nothrow_constructible_v<CallbackFn, Initializer>);template<class Initializer> explicit stop_callback(stop_token&& st, Initializer&& init) noexcept(is_nothrow_constructible_v<CallbackFn, Initializer>);

Constraints: CallbackFn and Initializer satisfyconstructible_from<CallbackFn, Initializer>.

Effects: Initializes callback-fn with std​::​forward<Initializer>(init)and executes a stoppable callback registration ([stoptoken.concepts]).

If a callback is registered with st's shared stop state, then *this acquires shared ownership of that stop state.

Effects: Executes a stoppable callback deregistration ([stoptoken.concepts]) and releases ownership of the stop state, if any.