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