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> 13 // tuple<Types&&...> forward_as_tuple(Types&&... t); 14 15 #include <tuple> 16 #include <cassert> 17 18 template <class Tuple> 19 void 20 test0(const Tuple& t) 21 { 22 static_assert(std::tuple_size<Tuple>::value == 0, ""); 23 } 24 25 template <class Tuple> 26 void 27 test1a(const Tuple& t) 28 { 29 static_assert(std::tuple_size<Tuple>::value == 1, ""); 30 static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&&>::value, ""); 31 assert(std::get<0>(t) == 1); 32 } 33 34 template <class Tuple> 35 void 36 test1b(const Tuple& t) 37 { 38 static_assert(std::tuple_size<Tuple>::value == 1, ""); 39 static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&>::value, ""); 40 assert(std::get<0>(t) == 2); 41 } 42 43 template <class Tuple> 44 void 45 test2a(const Tuple& t) 46 { 47 static_assert(std::tuple_size<Tuple>::value == 2, ""); 48 static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, double&>::value, ""); 49 static_assert(std::is_same<typename std::tuple_element<1, Tuple>::type, char&>::value, ""); 50 assert(std::get<0>(t) == 2.5); 51 assert(std::get<1>(t) == 'a'); 52 } 53 54 #if _LIBCPP_STD_VER > 11 55 template <class Tuple> 56 constexpr int 57 test3(const Tuple& t) 58 { 59 return std::tuple_size<Tuple>::value; 60 } 61 #endif 62 63 int main() 64 { 65 { 66 test0(std::forward_as_tuple()); 67 } 68 { 69 test1a(std::forward_as_tuple(1)); 70 } 71 { 72 int i = 2; 73 test1b(std::forward_as_tuple(i)); 74 } 75 { 76 double i = 2.5; 77 char c = 'a'; 78 test2a(std::forward_as_tuple(i, c)); 79 #if _LIBCPP_STD_VER > 11 80 static_assert ( test3 (std::forward_as_tuple(i, c)) == 2, "" ); 81 #endif 82 } 83 } 84