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