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