1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <tuple> 10 11 // template <class... Types> class tuple; 12 13 // template <class... UTypes> 14 // tuple& operator=(const tuple<UTypes...>& u); 15 16 // UNSUPPORTED: c++98, c++03 17 18 #include <tuple> 19 #include <string> 20 #include <cassert> 21 22 struct B 23 { 24 int id_; 25 26 explicit B(int i = 0) : id_(i) {} 27 }; 28 29 struct D 30 : B 31 { 32 explicit D(int i = 0) : B(i) {} 33 }; 34 35 int main() 36 { 37 { 38 typedef std::tuple<long> T0; 39 typedef std::tuple<long long> T1; 40 T0 t0(2); 41 T1 t1; 42 t1 = t0; 43 assert(std::get<0>(t1) == 2); 44 } 45 { 46 typedef std::tuple<long, char> T0; 47 typedef std::tuple<long long, int> T1; 48 T0 t0(2, 'a'); 49 T1 t1; 50 t1 = t0; 51 assert(std::get<0>(t1) == 2); 52 assert(std::get<1>(t1) == int('a')); 53 } 54 { 55 typedef std::tuple<long, char, D> T0; 56 typedef std::tuple<long long, int, B> T1; 57 T0 t0(2, 'a', D(3)); 58 T1 t1; 59 t1 = t0; 60 assert(std::get<0>(t1) == 2); 61 assert(std::get<1>(t1) == int('a')); 62 assert(std::get<2>(t1).id_ == 3); 63 } 64 { 65 D d(3); 66 D d2(2); 67 typedef std::tuple<long, char, D&> T0; 68 typedef std::tuple<long long, int, B&> T1; 69 T0 t0(2, 'a', d2); 70 T1 t1(1, 'b', d); 71 t1 = t0; 72 assert(std::get<0>(t1) == 2); 73 assert(std::get<1>(t1) == int('a')); 74 assert(std::get<2>(t1).id_ == 2); 75 } 76 { 77 // Test that tuple evaluates correctly applies an lvalue reference 78 // before evaluating is_assignable (ie 'is_assignable<int&, int&>') 79 // instead of evaluating 'is_assignable<int&&, int&>' which is false. 80 int x = 42; 81 int y = 43; 82 std::tuple<int&&> t(std::move(x)); 83 std::tuple<int&> t2(y); 84 t = t2; 85 assert(std::get<0>(t) == 43); 86 assert(&std::get<0>(t) == &x); 87 } 88 } 89