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