forward_as_tuple.pass.cpp 2.0 KB

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