1f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant//===----------------------------------------------------------------------===//
2f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant//
3f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant//                     The LLVM Compiler Infrastructure
4f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant//
5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// Source Licenses. See LICENSE.TXT for details.
7f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant//
8f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant//===----------------------------------------------------------------------===//
9f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant
10f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant// <future>
11f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant
12f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant// class promise<R>
13f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant
14f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant// void swap(promise& other);
15f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant
16f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant// template <class R> void swap(promise<R>& x, promise<R>& y);
17f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant
18f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant#include <future>
19f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant#include <cassert>
20f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant
21f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant#include "../test_allocator.h"
22f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant
23f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnantint main()
24f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant{
25f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    assert(test_alloc_base::count == 0);
26f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    {
27f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::promise<int> p0(std::allocator_arg, test_allocator<int>());
28f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::promise<int> p(std::allocator_arg, test_allocator<int>());
29f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 2);
30f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        p.swap(p0);
31f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 2);
32f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::future<int> f = p.get_future();
33f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 2);
34f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(f.valid());
35f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        f = p0.get_future();
36f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(f.valid());
37f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 2);
38f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    }
39f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    assert(test_alloc_base::count == 0);
40f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    {
41f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::promise<int> p0(std::allocator_arg, test_allocator<int>());
42f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::promise<int> p(std::allocator_arg, test_allocator<int>());
43f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 2);
44f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        swap(p, p0);
45f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 2);
46f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::future<int> f = p.get_future();
47f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 2);
48f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(f.valid());
49f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        f = p0.get_future();
50f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(f.valid());
51f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 2);
52f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    }
53f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    assert(test_alloc_base::count == 0);
54f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    {
55f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::promise<int> p0(std::allocator_arg, test_allocator<int>());
56f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::promise<int> p;
57f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 1);
58f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        p.swap(p0);
59f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 1);
60f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::future<int> f = p.get_future();
61f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 1);
62f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(f.valid());
63f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        f = p0.get_future();
64f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(f.valid());
65f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 1);
66f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    }
67f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    assert(test_alloc_base::count == 0);
68f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    {
69f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::promise<int> p0(std::allocator_arg, test_allocator<int>());
70f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::promise<int> p;
71f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 1);
72f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        swap(p, p0);
73f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 1);
74f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        std::future<int> f = p.get_future();
75f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 1);
76f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(f.valid());
77f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        f = p0.get_future();
78f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(f.valid());
79f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant        assert(test_alloc_base::count == 1);
80f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    }
81f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant    assert(test_alloc_base::count == 0);
82f39daa8e5a5f7d7eb19f391497a29b4fa0eec28dHoward Hinnant}
83