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
require the future object to have shared state as a precondition (they have undefined behaviour if valid() == false
). How then can a std::future
acquire some shared state and become useful?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
You do not normally use a
std::future
in isolation; you use it with astd::promise
. Thestd::promise
constructors set up some shared state. You can then use thestd::promise::get_future()
method to get astd::future
that refers to that shared state.