]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/thread/futures/futures.promise/move_assign.pass.cpp
Vendor import of libc++ trunk r256633:
[FreeBSD/FreeBSD.git] / test / std / thread / futures / futures.promise / move_assign.pass.cpp
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 // XFAIL: libcpp-no-exceptions
11 // UNSUPPORTED: libcpp-has-no-threads
12 // UNSUPPORTED: c++98, c++03
13
14 // <future>
15
16 // class promise<R>
17
18 // promise& operator=(promise&& rhs);
19
20 #include <future>
21 #include <cassert>
22
23 #include "test_allocator.h"
24
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         try
38         {
39             f = p0.get_future();
40             assert(false);
41         }
42         catch (const std::future_error& e)
43         {
44             assert(e.code() == make_error_code(std::future_errc::no_state));
45         }
46         assert(test_alloc_base::alloc_count == 1);
47     }
48     assert(test_alloc_base::alloc_count == 0);
49     {
50         std::promise<int&> p0(std::allocator_arg, test_allocator<int>());
51         std::promise<int&> p(std::allocator_arg, test_allocator<int>());
52         assert(test_alloc_base::alloc_count == 2);
53         p = std::move(p0);
54         assert(test_alloc_base::alloc_count == 1);
55         std::future<int&> f = p.get_future();
56         assert(test_alloc_base::alloc_count == 1);
57         assert(f.valid());
58         try
59         {
60             f = p0.get_future();
61             assert(false);
62         }
63         catch (const std::future_error& e)
64         {
65             assert(e.code() == make_error_code(std::future_errc::no_state));
66         }
67         assert(test_alloc_base::alloc_count == 1);
68     }
69     assert(test_alloc_base::alloc_count == 0);
70     {
71         std::promise<void> p0(std::allocator_arg, test_allocator<void>());
72         std::promise<void> p(std::allocator_arg, test_allocator<void>());
73         assert(test_alloc_base::alloc_count == 2);
74         p = std::move(p0);
75         assert(test_alloc_base::alloc_count == 1);
76         std::future<void> f = p.get_future();
77         assert(test_alloc_base::alloc_count == 1);
78         assert(f.valid());
79         try
80         {
81             f = p0.get_future();
82             assert(false);
83         }
84         catch (const std::future_error& e)
85         {
86             assert(e.code() == make_error_code(std::future_errc::no_state));
87         }
88         assert(test_alloc_base::alloc_count == 1);
89     }
90     assert(test_alloc_base::alloc_count == 0);
91 }