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 // tuple(tuple&& u); 15 16 // UNSUPPORTED: c++98, c++03 17 18 #include <tuple> 19 #include <utility> 20 #include <cassert> 21 22 #include "MoveOnly.h" 23 24 struct ConstructsWithTupleLeaf 25 { 26 ConstructsWithTupleLeaf() {} 27 28 ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); } 29 ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {} 30 31 template <class T> 32 ConstructsWithTupleLeaf(T t) { 33 static_assert(!std::is_same<T, T>::value, 34 "Constructor instantiated for type other than int"); 35 } 36 }; 37 38 int main() 39 { 40 { 41 typedef std::tuple<> T; 42 T t0; 43 T t = std::move(t0); 44 ((void)t); // Prevent unused warning 45 } 46 { 47 typedef std::tuple<MoveOnly> T; 48 T t0(MoveOnly(0)); 49 T t = std::move(t0); 50 assert(std::get<0>(t) == 0); 51 } 52 { 53 typedef std::tuple<MoveOnly, MoveOnly> T; 54 T t0(MoveOnly(0), MoveOnly(1)); 55 T t = std::move(t0); 56 assert(std::get<0>(t) == 0); 57 assert(std::get<1>(t) == 1); 58 } 59 { 60 typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; 61 T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); 62 T t = std::move(t0); 63 assert(std::get<0>(t) == 0); 64 assert(std::get<1>(t) == 1); 65 assert(std::get<2>(t) == 2); 66 } 67 // A bug in tuple caused __tuple_leaf to use its explicit converting constructor 68 // as its move constructor. This tests that ConstructsWithTupleLeaf is not called 69 // (w/ __tuple_leaf) 70 { 71 typedef std::tuple<ConstructsWithTupleLeaf> d_t; 72 d_t d((ConstructsWithTupleLeaf())); 73 d_t d2(static_cast<d_t &&>(d)); 74 } 75 } 76