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, const tuple<UTypes...>&);
16
17 // UNSUPPORTED: c++98, c++03
18
19 #include <tuple>
20 #include <memory>
21 #include <cassert>
22
23 #include "allocators.h"
24 #include "../alloc_first.h"
25 #include "../alloc_last.h"
26
27 struct Explicit {
28 int value;
ExplicitExplicit29 explicit Explicit(int x) : value(x) {}
30 };
31
32 struct Implicit {
33 int value;
ImplicitImplicit34 Implicit(int x) : value(x) {}
35 };
36
main()37 int main()
38 {
39 {
40 typedef std::tuple<long> T0;
41 typedef std::tuple<long long> T1;
42 T0 t0(2);
43 T1 t1(std::allocator_arg, A1<int>(), t0);
44 assert(std::get<0>(t1) == 2);
45 }
46 {
47 typedef std::tuple<int> T0;
48 typedef std::tuple<alloc_first> T1;
49 T0 t0(2);
50 alloc_first::allocator_constructed = false;
51 T1 t1(std::allocator_arg, A1<int>(5), t0);
52 assert(alloc_first::allocator_constructed);
53 assert(std::get<0>(t1) == 2);
54 }
55 {
56 typedef std::tuple<int, int> T0;
57 typedef std::tuple<alloc_first, alloc_last> T1;
58 T0 t0(2, 3);
59 alloc_first::allocator_constructed = false;
60 alloc_last::allocator_constructed = false;
61 T1 t1(std::allocator_arg, A1<int>(5), t0);
62 assert(alloc_first::allocator_constructed);
63 assert(alloc_last::allocator_constructed);
64 assert(std::get<0>(t1) == 2);
65 assert(std::get<1>(t1) == 3);
66 }
67 {
68 typedef std::tuple<long, int, int> T0;
69 typedef std::tuple<long long, alloc_first, alloc_last> T1;
70 T0 t0(1, 2, 3);
71 alloc_first::allocator_constructed = false;
72 alloc_last::allocator_constructed = false;
73 T1 t1(std::allocator_arg, A1<int>(5), t0);
74 assert(alloc_first::allocator_constructed);
75 assert(alloc_last::allocator_constructed);
76 assert(std::get<0>(t1) == 1);
77 assert(std::get<1>(t1) == 2);
78 assert(std::get<2>(t1) == 3);
79 }
80 {
81 const std::tuple<int> t1(42);
82 std::tuple<Explicit> t2{std::allocator_arg, std::allocator<void>{}, t1};
83 assert(std::get<0>(t2).value == 42);
84 }
85 {
86 const std::tuple<int> t1(42);
87 std::tuple<Implicit> t2 = {std::allocator_arg, std::allocator<void>{}, t1};
88 assert(std::get<0>(t2).value == 42);
89 }
90 }
91