forward_as_tuple.pass.cpp 2.0 KB

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