std::stop_c...top_callback(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… NAME πŸ’…

std::stop_callback::stop_callback - std::stop_callback::stop_callback

okay bestie, this page is from the C++ Standard Libary manual (yes, spelled exactly like that in the header, no cap), and the header title is std::stop_c...top_callback(3). It's the constructor page for std::stop_callback, and it's lowkey iconic πŸ’–


✨ SYNOPSIS ✨

template< class C >
explicit stop_callback( const std::stop_token& st, C&& cb )
(1) (since C++20)
noexcept(/*see below*/);
template< class C >
explicit stop_callback( std::stop_token&& st, C&& cb )
(2) (since C++20)
noexcept(/*see below*/);
stop_callback( const stop_callback& ) = delete;
(3) (since C++20)
stop_callback( stop_callback&& ) = delete;
(4) (since C++20)

okay so what's the vibe? Constructs a new stop_callback object, saving and registering the cb callback function into the given std::stop_token's associated stop-state, for later invocation if stop is requested on the associated std::stop_source. it's giving "hold my callback, I might need it later" energy πŸŽ€

  • 1) Constructs a stop_callback for the given st std::stop_token (copied), with the given invocable callback function cb.
  • 2) Constructs a stop_callback for the given st std::stop_token (moved), with the given invocable callback function cb.
  • 3,4) stop_callback is neither CopyConstructible nor MoveConstructible. periodt, it does not copy, it does not move πŸ’…

Both constructors participate in overload resolution only if Callback and C satisfy constructible_from of std::constructible_from<Callback, C>. and if Callback and C satisfy the concept but fail to satisfy its semantic requirement? bestie, that's undefined behavior πŸ’€


πŸ’– PARAMETERS πŸ’–

  • st β€” a std::stop_token object to register this stop_callback object with
  • cb β€” the type to invoke if stop is requested

😭 EXCEPTIONS 😭

1,2) here's the noexcept specification:

noexcept(std::is_nothrow_constructible_v<Callback, C>)

Any exception thrown by constructor-initializing the given callback into the stop_callback object β€” that's the exception situation, fr fr.


πŸ“ NOTES πŸ“

If st.stop_requested() == true for the passed-in std::stop_token, then the callback function is invoked in the current thread before the constructor returns. so yeah, it can run right there on the spot before the constructor is even done β€” main character energy 🫢


πŸ‘‘ CATEGORY πŸ‘‘

  • conditionally noexcept

that's the whole page, bestie 🫢 source/version: http://cppreference.com; date: 2024.06.10; page: std::stop_c...top_callback(3). go off and register those callbacks responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from