std::shared_future::valid(3)
π NAME π
Okay so bestie, welcome to std::shared_future::valid(3), straight from the C++ Standard Libary manual β yes, that's the spelling in the header, and we are respecting the typo π. The NAME is literally std::shared_future::valid - std::shared_future::valid; it's giving "I contain multitudes" energy π.
β¨ Synopsis β¨
bool valid() const noexcept; (since C++11)
Checks if the future refers to a shared state π«Ά. This is the case only for futures that were not default-constructed or moved from β no cap.
Unlike std::future, std::shared_future's shared state is not invalidated when get() is called. The way that survives get() is lowkey iconic π
.
π¨ Serious bestie warning: the behavior is undefined if any member function other than the destructor, the copy-assignment operator, the move-assignment operator, orvalidis called on ashared_futurethat does not refer to shared state. Implementations are encouraged to throwstd::future_errorindicatingno_statein this case β but that's encouragement, not a guarantee. Do not test this. It is not the vibe. π
It is valid to move or copy from a shared_future object for which valid() is false β that part is safe and slay π.
π Parameters π
(none) β literally no parameters. Zero. Zilch. Not even a little guy π.
πΈ Return value πΈ
true if *this refers to a shared state, otherwise false. That's it, that's the return value, and it understood the assignment β¨.
π¦ Example π¦
It says // Run this code, then it does this:
#include <future>
#include <iostream>
int main()
{
std::promise<void> p;
std::shared_future<void> f = p.get_future();
std::cout << std::boolalpha;
std::cout << f.valid() << '\n';
p.set_value();
std::cout << f.valid() << '\n';
f.get();
std::cout << f.valid() << '\n';
}
π Output π
true
true
true
π See also π
waitβ waits for the result to become available (public member function). That's the only see-also, and it's carrying the whole reference section on its back πͺ.
That's the whole page, bestie. It came from http://cppreference.com, dated 2024.06.10, and it's std::shared_future::valid(3) β bye, love u, 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