std::future

std::future is a template class that provides a mechanism to access the result of an asynchronous operation. To use std::future, first create a std::promise object that is used to set the value or exception that the std::future will eventually hold. The std::promise object creates a communication channel between the code that produces the result and the code that waits for the result.

Then, use the get_future() member function of the std::promise object to obtain a std::future object. This std::future object can be used to retrieve the value or exception associated with the std::promise object in a separate thread.

Once the std::future is obtained, you can use the std::future::get() method to block until the result is available and retrieve it. Alternatively, you can also check if the result is ready using std::future::wait_for() or std::future::wait_until() methods to avoid blocking indefinitely.