forward_as_tuple.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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 18template <class Tuple> 19void 20test0(const Tuple& t) 21{ 22 static_assert(std::tuple_size<Tuple>::value == 0, ""); 23} 24 25template <class Tuple> 26void 27test1a(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 34template <class Tuple> 35void 36test1b(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 43template <class Tuple> 44void 45test2a(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 54int main() 55{ 56 { 57 test0(std::forward_as_tuple()); 58 } 59 { 60 test1a(std::forward_as_tuple(1)); 61 } 62 { 63 int i = 2; 64 test1b(std::forward_as_tuple(i)); 65 } 66 { 67 double i = 2.5; 68 char c = 'a'; 69 test2a(std::forward_as_tuple(i, c)); 70 } 71} 72