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