forward_as_tuple.pass.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. 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 <cassert>
  14. template <class Tuple>
  15. void
  16. test0(const Tuple& t)
  17. {
  18. static_assert(std::tuple_size<Tuple>::value == 0, "");
  19. }
  20. template <class Tuple>
  21. void
  22. test1a(const Tuple& t)
  23. {
  24. static_assert(std::tuple_size<Tuple>::value == 1, "");
  25. static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&&>::value, "");
  26. assert(std::get<0>(t) == 1);
  27. }
  28. template <class Tuple>
  29. void
  30. test1b(const Tuple& t)
  31. {
  32. static_assert(std::tuple_size<Tuple>::value == 1, "");
  33. static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&>::value, "");
  34. assert(std::get<0>(t) == 2);
  35. }
  36. template <class Tuple>
  37. void
  38. test2a(const Tuple& t)
  39. {
  40. static_assert(std::tuple_size<Tuple>::value == 2, "");
  41. static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, double&>::value, "");
  42. static_assert(std::is_same<typename std::tuple_element<1, Tuple>::type, char&>::value, "");
  43. assert(std::get<0>(t) == 2.5);
  44. assert(std::get<1>(t) == 'a');
  45. }
  46. int main()
  47. {
  48. {
  49. test0(std::forward_as_tuple());
  50. }
  51. {
  52. test1a(std::forward_as_tuple(1));
  53. }
  54. {
  55. int i = 2;
  56. test1b(std::forward_as_tuple(i));
  57. }
  58. {
  59. double i = 2.5;
  60. char c = 'a';
  61. test2a(std::forward_as_tuple(i, c));
  62. }
  63. }