• 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 // void swap(promise& other);
15 
16 // template <class R> void swap(promise<R>& x, promise<R>& y);
17 
18 #include <future>
19 #include <cassert>
20 
21 #include "../test_allocator.h"
22 
main()23 int main()
24 {
25     assert(test_alloc_base::count == 0);
26     {
27         std::promise<int> p0(std::allocator_arg, test_allocator<int>());
28         std::promise<int> p(std::allocator_arg, test_allocator<int>());
29         assert(test_alloc_base::count == 2);
30         p.swap(p0);
31         assert(test_alloc_base::count == 2);
32         std::future<int> f = p.get_future();
33         assert(test_alloc_base::count == 2);
34         assert(f.valid());
35         f = p0.get_future();
36         assert(f.valid());
37         assert(test_alloc_base::count == 2);
38     }
39     assert(test_alloc_base::count == 0);
40     {
41         std::promise<int> p0(std::allocator_arg, test_allocator<int>());
42         std::promise<int> p(std::allocator_arg, test_allocator<int>());
43         assert(test_alloc_base::count == 2);
44         swap(p, p0);
45         assert(test_alloc_base::count == 2);
46         std::future<int> f = p.get_future();
47         assert(test_alloc_base::count == 2);
48         assert(f.valid());
49         f = p0.get_future();
50         assert(f.valid());
51         assert(test_alloc_base::count == 2);
52     }
53     assert(test_alloc_base::count == 0);
54     {
55         std::promise<int> p0(std::allocator_arg, test_allocator<int>());
56         std::promise<int> p;
57         assert(test_alloc_base::count == 1);
58         p.swap(p0);
59         assert(test_alloc_base::count == 1);
60         std::future<int> f = p.get_future();
61         assert(test_alloc_base::count == 1);
62         assert(f.valid());
63         f = p0.get_future();
64         assert(f.valid());
65         assert(test_alloc_base::count == 1);
66     }
67     assert(test_alloc_base::count == 0);
68     {
69         std::promise<int> p0(std::allocator_arg, test_allocator<int>());
70         std::promise<int> p;
71         assert(test_alloc_base::count == 1);
72         swap(p, p0);
73         assert(test_alloc_base::count == 1);
74         std::future<int> f = p.get_future();
75         assert(test_alloc_base::count == 1);
76         assert(f.valid());
77         f = p0.get_future();
78         assert(f.valid());
79         assert(test_alloc_base::count == 1);
80     }
81     assert(test_alloc_base::count == 0);
82 }
83