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 // UNSUPPORTED: libcpp-has-no-threads
     11 
     12 // <future>
     13 
     14 // class promise<R>
     15 
     16 // void promise::set_value_at_thread_exit(R&& r);
     17 
     18 #include <future>
     19 #include <memory>
     20 #include <cassert>
     21 
     22 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     23 
     24 void func(std::promise<std::unique_ptr<int>> p)
     25 {
     26     p.set_value_at_thread_exit(std::unique_ptr<int>(new int(5)));
     27 }
     28 
     29 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     30 
     31 int main()
     32 {
     33 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     34     {
     35         std::promise<std::unique_ptr<int>> p;
     36         std::future<std::unique_ptr<int>> f = p.get_future();
     37         std::thread(func, std::move(p)).detach();
     38         assert(*f.get() == 5);
     39     }
     40 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     41 }
     42