just::thread Complete C++ Standard Thread Library by Just Software Solutions

Documentation Home >> Headers >> <future> Header >> std::promise class template

The std::promise class template provides a means of setting an asynchronous result, which may be retrieved from another thread through an instance of std::future.

The ResultType template parameter is the type of the value that can be stored in the asynchronous result.

A std::future associated with the asynchronous result of a particular std::promise instance can be obtained by calling the get_future() member function. The asynchronous result is either set to a value of type ResultType with the set_value() member function, or to an exception with the set_exception() member function.

Instances of std::promise are MoveConstructible and MoveAssignable, but not CopyConstructible or CopyAssignable.

template<typename ResultType>
class promise
{
public:
    promise();
    promise(promise&&);
    ~promise();
    promise& operator=(promise&&);

    template<typename Allocator>
    promise(std::allocator_arg_t, Allocator const&);

    promise(promise const&) = delete;
    promise& operator=(promise const&) = delete;

    void swap(promise& );

    std::future<ResultType> get_future();

    void set_value(see description);
    void set_exception(std::exception_ptr p);
};
Header

#include <future>

See Also