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> 15 // tuple& operator=(tuple<UTypes...>&& u); 16 17 #include <tuple> 18 #include <string> 19 #include <memory> 20 #include <cassert> 21 22 struct B 23 { 24 int id_; 25 26 explicit B(int i= 0) : id_(i) {} 27 28 virtual ~B() {} 29 }; 30 31 struct D 32 : B 33 { 34 explicit D(int i) : B(i) {} 35 }; 36 37 int main() 38 { 39 { 40 typedef std::tuple<double> T0; 41 typedef std::tuple<int> T1; 42 T0 t0(2.5); 43 T1 t1; 44 t1 = std::move(t0); 45 assert(std::get<0>(t1) == 2); 46 } 47 { 48 typedef std::tuple<double, char> T0; 49 typedef std::tuple<int, int> T1; 50 T0 t0(2.5, 'a'); 51 T1 t1; 52 t1 = std::move(t0); 53 assert(std::get<0>(t1) == 2); 54 assert(std::get<1>(t1) == int('a')); 55 } 56 { 57 typedef std::tuple<double, char, D> T0; 58 typedef std::tuple<int, int, B> T1; 59 T0 t0(2.5, 'a', D(3)); 60 T1 t1; 61 t1 = std::move(t0); 62 assert(std::get<0>(t1) == 2); 63 assert(std::get<1>(t1) == int('a')); 64 assert(std::get<2>(t1).id_ == 3); 65 } 66 { 67 D d(3); 68 D d2(2); 69 typedef std::tuple<double, char, D&> T0; 70 typedef std::tuple<int, int, B&> T1; 71 T0 t0(2.5, 'a', d2); 72 T1 t1(1.5, 'b', d); 73 t1 = std::move(t0); 74 assert(std::get<0>(t1) == 2); 75 assert(std::get<1>(t1) == int('a')); 76 assert(std::get<2>(t1).id_ == 2); 77 } 78 { 79 typedef std::tuple<double, char, std::unique_ptr<D>> T0; 80 typedef std::tuple<int, int, std::unique_ptr<B>> T1; 81 T0 t0(2.5, 'a', std::unique_ptr<D>(new D(3))); 82 T1 t1; 83 t1 = std::move(t0); 84 assert(std::get<0>(t1) == 2); 85 assert(std::get<1>(t1) == int('a')); 86 assert(std::get<2>(t1)->id_ == 3); 87 } 88 } 89