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