是什么给了 std::future 一些共享状态
What gives a std::future some shared state
A std::future
has a std::future::valid
method, which indicates whether the future object refers to some shared state. None of the constructors construct a future object that refers to shared state (except the move constructor, which can move the shared state from one future object to another). All the methods of the class (get
, wait
, wait_for
and wait_until
要求未来对象具有共享状态作为先决条件(如果 valid() == false
它们具有未定义的行为)。 std::future
如何获得一些 共享状态 并变得有用?
您通常不会单独使用 std::future
;您将它与 std::promise
. The std::promise
constructors set up some shared state. You can then use the std::promise::get_future()
方法一起使用以获得引用 共享状态 .
的 std::future
A std::future
has a std::future::valid
method, which indicates whether the future object refers to some shared state. None of the constructors construct a future object that refers to shared state (except the move constructor, which can move the shared state from one future object to another). All the methods of the class (get
, wait
, wait_for
and wait_until
要求未来对象具有共享状态作为先决条件(如果 valid() == false
它们具有未定义的行为)。 std::future
如何获得一些 共享状态 并变得有用?
您通常不会单独使用 std::future
;您将它与 std::promise
. The std::promise
constructors set up some shared state. You can then use the std::promise::get_future()
方法一起使用以获得引用 共享状态 .
std::future