forward_as_tuple.pass.cpp 2.0 KB

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