Files
cppdraft_translate/cppdraft/stopcallback.md
2025-10-25 03:02:53 +03:00

4.2 KiB
Raw Permalink Blame History

[stopcallback]

32 Concurrency support library [thread]

32.3 Stop tokens [thread.stoptoken]

32.3.6 Class template stop_callback [stopcallback]

32.3.6.1 General [stopcallback.general]

1

#

🔗

namespace std {templateclass stop_callback {public:using callback_type = CallbackFn; // [stopcallback.cons], constructors and destructortemplateexplicit stop_callback(const stop_token& st, Initializer&& init)noexcept(is_nothrow_constructible_v<CallbackFn, Initializer>); templateexplicit 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; // exposition only}; template stop_callback(stop_token, CallbackFn) -> stop_callback;}

2

#

Mandates: stop_callback is instantiated with an argument for the template parameter CallbackFn that satisfies both invocable and destructible.

3

#

Remarks: For a type Initializer, ifstoppable-callback-for<CallbackFn, stop_token, Initializer> is satisfied, thenstoppable-callback-for<CallbackFn, stop_token, Initializer> is modeled.

The exposition-only callback-fn member is the associated callback function ([stoptoken.concepts]) ofstop_callback<
CallbackFn> objects.

32.3.6.2 Constructors and destructor [stopcallback.cons]

🔗

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

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

1

#

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

2

#

Effects: Initializes callback-fn with std::forward(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.

🔗

~stop_callback();

3

#

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