| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// <tuple> |
| 10 |
|
| 11 |
// template<class... Types> |
| 12 |
// tuple<Types&&...> forward_as_tuple(Types&&... t); |
| 13 |
|
| 14 |
// UNSUPPORTED: c++03 |
| 15 |
|
| 16 |
#include <tuple> |
| 17 |
#include <type_traits> |
| 18 |
#include <cassert> |
| 19 |
|
| 20 |
#include "test_macros.h" |
| 21 |
|
| 22 |
template <class Tuple> |
| 23 |
void |
| 24 |
test0(const Tuple&) |
| 25 |
{ |
| 26 |
static_assert(std::tuple_size<Tuple>::value == 0, ""); |
| 27 |
} |
| 28 |
|
| 29 |
template <class Tuple> |
| 30 |
void |
| 31 |
test1a(const Tuple& t) |
| 32 |
{ |
| 33 |
static_assert(std::tuple_size<Tuple>::value == 1, ""); |
| 34 |
static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&&>::value, ""); |
| 35 |
assert(std::get<0>(t) == 1); |
| 36 |
} |
| 37 |
|
| 38 |
template <class Tuple> |
| 39 |
void |
| 40 |
test1b(const Tuple& t) |
| 41 |
{ |
| 42 |
static_assert(std::tuple_size<Tuple>::value == 1, ""); |
| 43 |
static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&>::value, ""); |
| 44 |
assert(std::get<0>(t) == 2); |
| 45 |
} |
| 46 |
|
| 47 |
template <class Tuple> |
| 48 |
void |
| 49 |
test2a(const Tuple& t) |
| 50 |
{ |
| 51 |
static_assert(std::tuple_size<Tuple>::value == 2, ""); |
| 52 |
static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, double&>::value, ""); |
| 53 |
static_assert(std::is_same<typename std::tuple_element<1, Tuple>::type, char&>::value, ""); |
| 54 |
assert(std::get<0>(t) == 2.5); |
| 55 |
assert(std::get<1>(t) == 'a'); |
| 56 |
} |
| 57 |
|
| 58 |
#if TEST_STD_VER > 11 |
| 59 |
template <class Tuple> |
| 60 |
constexpr int |
| 61 |
test3(const Tuple&) |
| 62 |
{ |
| 63 |
return std::tuple_size<Tuple>::value; |
| 64 |
} |
| 65 |
#endif |
| 66 |
|
| 67 |
int main(int, char**) |
| 68 |
{ |
| 69 |
{ |
| 70 |
test0(std::forward_as_tuple()); |
| 71 |
} |
| 72 |
{ |
| 73 |
test1a(std::forward_as_tuple(1)); |
| 74 |
} |
| 75 |
{ |
| 76 |
int i = 2; |
| 77 |
test1b(std::forward_as_tuple(i)); |
| 78 |
} |
| 79 |
{ |
| 80 |
double i = 2.5; |
| 81 |
char c = 'a'; |
| 82 |
test2a(std::forward_as_tuple(i, c)); |
| 83 |
#if TEST_STD_VER > 11 |
| 84 |
static_assert ( test3 (std::forward_as_tuple(i, c)) == 2, "" ); |
| 85 |
#endif |
| 86 |
} |
| 87 |
|
| 88 |
return 0; |
| 89 |
} |