std::corout...utine_handle(3)

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

✨ NAME ✨

std::coroutine_handle::coroutine_handle β€” bestie, it's literally the constructor of std::coroutine_handle πŸ’… (and yeah, the page title is std::corout...utine_handle(3) from the C++ Standard Library manual, we're keeping it real πŸŽ€)


✨ Synopsis ✨

Okay so here's the whole lineup, no cap:

constexpr coroutine_handle() noexcept;                       (1)
(since C++20)
constexpr coroutine_handle( std::nullptr_t ) noexcept;       (2)
(since C++20)
coroutine_handle( const coroutine_handle& other ) = default; (3)
(since C++20)
coroutine_handle( coroutine_handle&& other ) = default;      (4)
(since C++20)

So what do these do? They create a coroutine_handle that does not refer to a coroutine, or they copy an existing coroutine_handle. That's the whole vibe πŸ¦‹

  • (1), (2) β€” these initialize the underlying address ptr to nullptr. After construction, address() returns nullptr, and the coroutine_handle doesn't refer to a coroutine, periodt. ⚠️ Heads up though: these constructors are not declared for the specialization std::coroutine_handle<std::noop_coroutine_promise>.
  • (3), (4) β€” these copy the underlying address. The copy constructor and move constructor are equivalent to implicitly declared ones. Iconic, honestly 🌸

✨ Parameters ✨

  • other β€” another coroutine_handle to copy 🫢

✨ Notes ✨

std::coroutine_handle<std::noop_coroutine_promise> is neither default constructible nor constructible from std::nullptr_t. Like, at all. πŸ™ˆ But bestie, don't panic β€” std::noop_coroutine can be used to create a new std::coroutine_handle<std::noop_coroutine_promise>. Slay.

Also, the static member functions from_promise and from_address can create a coroutine_handle too, iykyk πŸ’œ


✨ See also ✨

  • from_promise β€” creates a coroutine_handle from the promise object of a coroutine. [static] (C++20) (public static member function) ⭐
  • from_address β€” imports a coroutine from a pointer. [static] (C++20) (public static member function) πŸ”₯
  • noop_coroutine (C++20) β€” creates a coroutine handle that has no observable effects when resumed or destroyed. (function) β€” literally the chillest handle ever πŸ’€

Go forth and construct responsibly, bestie. The nullptr ones are noexcept, so at least you can't get caught lacking by an exception there πŸ˜­πŸ‘‘

That's the whole page, mwah πŸ’– Sourced straight from http://cppreference.com, dated 2024.06.10 β€” and that header/footer combo was the std::corout...utine_handle(3) page itself, so you know it's legit. Catch you in the next manpage, babe πŸ§šπŸ“

πŸ“¦ where this page comes from