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