std::future::share(3)

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

πŸ’… NAME

okay so this is the std::future::share(3) page from the C++ Standard Libary, and it's literally about moving a future's shared state into a std::shared_future so multiple besties can reference it. no cap, it's giving very specific but very iconic C++ energy πŸ’–


✨ Synopsis

std::shared_future<T> share() noexcept;

Transfers the shared state of *this, if any, to a std::shared_future object. Multiple std::shared_future objects may reference the same shared state, which is not possible with std::future. After calling share on a std::future, valid() == false.

lowkey important: once you call share on a std::future, that future is not valid anymore. valid() == false, periodt.

πŸŽ€ Parameters

(none) β€” not a single parameter, bestie. zero. nada. the parameter list is empty and it's thriving 🫢


πŸ’– Return value

A std::shared_future object containing the shared state previously held by *this, if any, constructed as if by std::shared_future<T>(std::move(*this)).


πŸ¦‹ Example

This section is incomplete.

Reason: no example.

not me reading β€œThis section is incomplete” in the actual docs 😭 no example exists on this page, so we're not making one up. facts are facts.

🌸 Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

  • LWG 2556 β€” applied to C++11; behavior as published: share() requires valid() to be true; correct behavior: requirement removed and made noexcept.

🌈 See also

  • shared_future (C++11) β€” waits for a value (possibly referenced by other futures) that is set asynchronously (class template).

πŸ‘‘ Category

  • Todo β€” no example

source/version + date check: http://cppreference.com, 2024.06.10, page std::future::share(3) β€” bye bestie, go share that state responsibly βœ¨πŸ’…

πŸ“¦ where this page comes from