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