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