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 // promise& operator=(promise&& rhs);
     17 
     18 #include <future>
     19 #include <cassert>
     20 
     21 #include "../test_allocator.h"
     22 
     23 int main()
     24 {
     25 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     26     assert(test_alloc_base::count == 0);
     27     {
     28         std::promise<int> p0(std::allocator_arg, test_allocator<int>());
     29         std::promise<int> p(std::allocator_arg, test_allocator<int>());
     30         assert(test_alloc_base::count == 2);
     31         p = std::move(p0);
     32         assert(test_alloc_base::count == 1);
     33         std::future<int> f = p.get_future();
     34         assert(test_alloc_base::count == 1);
     35         assert(f.valid());
     36         try
     37         {
     38             f = p0.get_future();
     39             assert(false);
     40         }
     41         catch (const std::future_error& e)
     42         {
     43             assert(e.code() == make_error_code(std::future_errc::no_state));
     44         }
     45         assert(test_alloc_base::count == 1);
     46     }
     47     assert(test_alloc_base::count == 0);
     48     {
     49         std::promise<int&> p0(std::allocator_arg, test_allocator<int>());
     50         std::promise<int&> p(std::allocator_arg, test_allocator<int>());
     51         assert(test_alloc_base::count == 2);
     52         p = std::move(p0);
     53         assert(test_alloc_base::count == 1);
     54         std::future<int&> f = p.get_future();
     55         assert(test_alloc_base::count == 1);
     56         assert(f.valid());
     57         try
     58         {
     59             f = p0.get_future();
     60             assert(false);
     61         }
     62         catch (const std::future_error& e)
     63         {
     64             assert(e.code() == make_error_code(std::future_errc::no_state));
     65         }
     66         assert(test_alloc_base::count == 1);
     67     }
     68     assert(test_alloc_base::count == 0);
     69     {
     70         std::promise<void> p0(std::allocator_arg, test_allocator<void>());
     71         std::promise<void> p(std::allocator_arg, test_allocator<void>());
     72         assert(test_alloc_base::count == 2);
     73         p = std::move(p0);
     74         assert(test_alloc_base::count == 1);
     75         std::future<void> f = p.get_future();
     76         assert(test_alloc_base::count == 1);
     77         assert(f.valid());
     78         try
     79         {
     80             f = p0.get_future();
     81             assert(false);
     82         }
     83         catch (const std::future_error& e)
     84         {
     85             assert(e.code() == make_error_code(std::future_errc::no_state));
     86         }
     87         assert(test_alloc_base::count == 1);
     88     }
     89     assert(test_alloc_base::count == 0);
     90 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     91 }
     92