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