fork(4) download
  1. #include <iostream>
  2. #include <future>
  3. #include <functional>
  4.  
  5. int main() {
  6. std::future<int> f;
  7. {
  8. std::packaged_task<int()> task([](){return 3; });
  9. f = task.get_future();
  10. }
  11. std::cout<<f.get()<<std::endl;
  12. return 0;
  13. }
Runtime error #stdin #stdout #stderr 0s 3480KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::future_error'
  what():  Broken promise