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... UTypes> tuple(const tuple<UTypes...>& u);
15 
16 #include <tuple>
17 #include <string>
18 #include <cassert>
19 
20 struct B
21 {
22     int id_;
23 
24     explicit B(int i) : id_(i) {}
25 };
26 
27 struct D
28     : B
29 {
30     explicit D(int i) : B(i) {}
31 };
32 
33 #if _LIBCPP_STD_VER > 11
34 
35 struct A
36 {
37     int id_;
38 
39     constexpr A(int i) : id_(i) {}
40     friend constexpr bool operator==(const A& x, const A& y) {return x.id_ == y.id_;}
41 };
42 
43 struct C
44 {
45     int id_;
46 
47     constexpr explicit C(int i) : id_(i) {}
48     friend constexpr bool operator==(const C& x, const C& y) {return x.id_ == y.id_;}
49 };
50 
51 #endif
52 
53 int main()
54 {
55     {
56         typedef std::tuple<double> T0;
57         typedef std::tuple<int> T1;
58         T0 t0(2.5);
59         T1 t1 = t0;
60         assert(std::get<0>(t1) == 2);
61     }
62 #if _LIBCPP_STD_VER > 11
63     {
64         typedef std::tuple<double> T0;
65         typedef std::tuple<A> T1;
66         constexpr T0 t0(2.5);
67         constexpr T1 t1 = t0;
68         static_assert(std::get<0>(t1) == 2, "");
69     }
70     {
71         typedef std::tuple<int> T0;
72         typedef std::tuple<C> T1;
73         constexpr T0 t0(2);
74         constexpr T1 t1{t0};
75         static_assert(std::get<0>(t1) == C(2), "");
76     }
77 #endif
78     {
79         typedef std::tuple<double, char> T0;
80         typedef std::tuple<int, int> T1;
81         T0 t0(2.5, 'a');
82         T1 t1 = t0;
83         assert(std::get<0>(t1) == 2);
84         assert(std::get<1>(t1) == int('a'));
85     }
86     {
87         typedef std::tuple<double, char, D> T0;
88         typedef std::tuple<int, int, B> T1;
89         T0 t0(2.5, 'a', D(3));
90         T1 t1 = t0;
91         assert(std::get<0>(t1) == 2);
92         assert(std::get<1>(t1) == int('a'));
93         assert(std::get<2>(t1).id_ == 3);
94     }
95     {
96         D d(3);
97         typedef std::tuple<double, char, D&> T0;
98         typedef std::tuple<int, int, B&> T1;
99         T0 t0(2.5, 'a', d);
100         T1 t1 = t0;
101         d.id_ = 2;
102         assert(std::get<0>(t1) == 2);
103         assert(std::get<1>(t1) == int('a'));
104         assert(std::get<2>(t1).id_ == 2);
105     }
106     {
107         typedef std::tuple<double, char, int> T0;
108         typedef std::tuple<int, int, B> T1;
109         T0 t0(2.5, 'a', 3);
110         T1 t1(t0);
111         assert(std::get<0>(t1) == 2);
112         assert(std::get<1>(t1) == int('a'));
113         assert(std::get<2>(t1).id_ == 3);
114     }
115 }
116