std::future::valid(3)
π std::future::valid π
okay so bestie, welcome to the C++ Standard Libary manual β this page is literally std::future::valid(3), and itβs giving tiny bool, big consequences energy. π«Ά
β¨ NAME β¨
std::future::valid - std::future::valid
πΈ Synopsis πΈ
bool valid() const noexcept; (since C++11)
Checks if the future refers to a shared state. Yes, thatβs the whole assignment. π
This is the case only for futures that were not default-constructed or moved from β like the ones returned by std::promise::get_future(), std::packaged_task::get_future() or std::async() β until the first time get() or share() is called. β³
π¨ The behavior is undefined if any member function other than the destructor, the move-assignment operator, or valid is called on a future that does not refer to shared state (although implementations are encouraged to throw std::future_error indicating no_state in this case). It is valid to move from a future object for which valid() is false. No cap.
π Parameters π
(none) β she takes no parameters, periodt. π
π« Return value π«
true if *this refers to a shared state, otherwise false.
π¦ Example π¦
// Run this code
#include <future>
#include <iostream>
int main()
{
std::promise<void> p;
std::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
false
π See also π
waitβ waits for the result to become available (public member function)
xoxo, your C++ bestie π β source: http://cppreference.com, version/date: 2024.06.10, page: std::future::valid(3). 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