Home | History | Annotate | Download | only in futures.promise
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <future>
     11 
     12 // class promise<R>
     13 
     14 // void promise::set_value_at_thread_exit(R&& r);
     15 
     16 #include <future>
     17 #include <memory>
     18 #include <cassert>
     19 
     20 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     21 
     22 void func(std::promise<std::unique_ptr<int>> p)
     23 {
     24     p.set_value_at_thread_exit(std::unique_ptr<int>(new int(5)));
     25 }
     26 
     27 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     28 
     29 int main()
     30 {
     31 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     32     {
     33         std::promise<std::unique_ptr<int>> p;
     34         std::future<std::unique_ptr<int>> f = p.get_future();
     35         std::thread(func, std::move(p)).detach();
     36         assert(*f.get() == 5);
     37     }
     38 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     39 }
     40