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 // <tuple>
11
12 // template <class... Types> class tuple;
13
14 // template <class Alloc, class... UTypes>
15 // tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&);
16
17 #include <tuple>
18 #include <string>
19 #include <memory>
20 #include <cassert>
21
22 #include "allocators.h"
23 #include "../alloc_first.h"
24 #include "../alloc_last.h"
25
26 struct B
27 {
28 int id_;
29
BB30 explicit B(int i) : id_(i) {}
31
~BB32 virtual ~B() {}
33 };
34
35 struct D
36 : B
37 {
DD38 explicit D(int i) : B(i) {}
39 };
40
main()41 int main()
42 {
43 {
44 typedef std::tuple<int> T0;
45 typedef std::tuple<alloc_first> T1;
46 T0 t0(2);
47 alloc_first::allocator_constructed = false;
48 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
49 assert(alloc_first::allocator_constructed);
50 assert(std::get<0>(t1) == 2);
51 }
52 {
53 typedef std::tuple<std::unique_ptr<D>> T0;
54 typedef std::tuple<std::unique_ptr<B>> T1;
55 T0 t0(std::unique_ptr<D>(new D(3)));
56 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
57 assert(std::get<0>(t1)->id_ == 3);
58 }
59 {
60 typedef std::tuple<int, std::unique_ptr<D>> T0;
61 typedef std::tuple<alloc_first, std::unique_ptr<B>> T1;
62 T0 t0(2, std::unique_ptr<D>(new D(3)));
63 alloc_first::allocator_constructed = false;
64 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
65 assert(alloc_first::allocator_constructed);
66 assert(std::get<0>(t1) == 2);
67 assert(std::get<1>(t1)->id_ == 3);
68 }
69 {
70 typedef std::tuple<int, int, std::unique_ptr<D>> T0;
71 typedef std::tuple<alloc_last, alloc_first, std::unique_ptr<B>> T1;
72 T0 t0(1, 2, std::unique_ptr<D>(new D(3)));
73 alloc_first::allocator_constructed = false;
74 alloc_last::allocator_constructed = false;
75 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
76 assert(alloc_first::allocator_constructed);
77 assert(alloc_last::allocator_constructed);
78 assert(std::get<0>(t1) == 1);
79 assert(std::get<1>(t1) == 2);
80 assert(std::get<2>(t1)->id_ == 3);
81 }
82 }
83