#include#include int foo(int a, int b) { return a + b; } int main() { std::future fut = std::async(foo, 2, 3); int result = fut.get(); std::cout << "Result: " << result << std::endl; return 0; }
#includePackage Library: The C++ Future library is part of the C++ Standard Library and does not require any external packages or libraries.#include void func(std::promise & p) { // Do some work here p.set_value(42); } int main() { std::promise p; std::future fut = p.get_future(); std::thread t(func, std::ref(p)); int result = fut.get(); t.join(); std::cout << "Result: " << result << std::endl; return 0; }