std::experi...uture::then(3)
π std::experimental::shared_future::then π
ok so real talk, this page is from the C++ Standard Library manual, section 3 β yes the header literally says std::experi...uture::then(3) because they truncated it, we love an abbreviated queen β¨
NAME πΈ
std::experimental::shared_future::then β and yeah, the page says it twice in a row. That's just how it is, bestie. It's <pink>std::experimental::shared_future::then</pink>, no cap.
Synopsis π
template< class F >
future</* see below */> then( F&& func ) const;
So here's the tea π β what this actually does is attach the continuation func to *this.
Heads up, the behavior is undefined if *this has no associated shared state (like, valid() == false). That's not a cute look, don't do it π
It creates a shared state associated with the future object to be returned, and a copy fd of func constructed as if by DECAY_COPY(std::forward<F>(func)) evaluated in the thread calling then, where DECAY_COPY is defined as:
template<class T>
std::decay_t<T> DECAY_COPY(T&& v)
{
return std::forward<T>(v);
}
When the shared state currently associated with *this is ready, the continuation INVOKE(std::move(fd), *this) is called on an unspecified thread of execution, where INVOKE is the operation defined in Callable. If that expression is invalid, the behavior is undefined π (yes, again β it's giving "undefined behavior is my whole personality").
Any value returned from the continuation is stored as the result in the shared state of the returned future object. Any exception propagated from the execution of the continuation is stored as the exceptional result in the shared state of the returned future object. like, errors get caught and stored properly, we stay winning β¨
Let U be the return type of the continuation (i.e. std::result_of_t<std::decay_t<F>(const std::experimental::shared_future<T> &)>). If U is std::experimental::future<T2> for some type T2, then the return type of then is std::experimental::future<T2>, otherwise it is std::experimental::future<U>. This is known as implicit unwrapping π β iconic name honestly.
And if implicit unwrapping takes place and the continuation returns an invalid future, then the shared state is made ready with an exception of type std::future_error with an error condition of std::future_errc::broken_promise π
After this function returns, valid() is true π periodt.
Parameters π«Ά
funcβ a continuation to be attached π
Return value π
A std::experimental::future object associated with the shared state created by this object. And valid() == true for the returned object. slay.
Example π¦
This section is incomplete π Reason: no example
Category π
- Todo no example
and that's the whole page bestie, no notes π β courtesy of http://cppreference.com, doc version 2024.06.10, dated 2024.06.10, and yeah the footer's still yelling std::experi...uture::then(3) at us on the way out. mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms