get_const_rv.pass.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // <tuple>
  9. // template <class... Types> class tuple;
  10. // template <size_t I, class... Types>
  11. // const typename tuple_element<I, tuple<Types...> >::type&&
  12. // get(const tuple<Types...>&& t);
  13. // UNSUPPORTED: c++98, c++03
  14. #include <tuple>
  15. #include <utility>
  16. #include <string>
  17. #include <type_traits>
  18. #include <cassert>
  19. #include "test_macros.h"
  20. int main(int, char**)
  21. {
  22. {
  23. typedef std::tuple<int> T;
  24. const T t(3);
  25. static_assert(std::is_same<const int&&, decltype(std::get<0>(std::move(t)))>::value, "");
  26. static_assert(noexcept(std::get<0>(std::move(t))), "");
  27. const int&& i = std::get<0>(std::move(t));
  28. assert(i == 3);
  29. }
  30. {
  31. typedef std::tuple<std::string, int> T;
  32. const T t("high", 5);
  33. static_assert(std::is_same<const std::string&&, decltype(std::get<0>(std::move(t)))>::value, "");
  34. static_assert(noexcept(std::get<0>(std::move(t))), "");
  35. static_assert(std::is_same<const int&&, decltype(std::get<1>(std::move(t)))>::value, "");
  36. static_assert(noexcept(std::get<1>(std::move(t))), "");
  37. const std::string&& s = std::get<0>(std::move(t));
  38. const int&& i = std::get<1>(std::move(t));
  39. assert(s == "high");
  40. assert(i == 5);
  41. }
  42. {
  43. int x = 42;
  44. int const y = 43;
  45. std::tuple<int&, int const&> const p(x, y);
  46. static_assert(std::is_same<int&, decltype(std::get<0>(std::move(p)))>::value, "");
  47. static_assert(noexcept(std::get<0>(std::move(p))), "");
  48. static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, "");
  49. static_assert(noexcept(std::get<1>(std::move(p))), "");
  50. }
  51. {
  52. int x = 42;
  53. int const y = 43;
  54. std::tuple<int&&, int const&&> const p(std::move(x), std::move(y));
  55. static_assert(std::is_same<int&&, decltype(std::get<0>(std::move(p)))>::value, "");
  56. static_assert(noexcept(std::get<0>(std::move(p))), "");
  57. static_assert(std::is_same<int const&&, decltype(std::get<1>(std::move(p)))>::value, "");
  58. static_assert(noexcept(std::get<1>(std::move(p))), "");
  59. }
  60. #if TEST_STD_VER > 11
  61. {
  62. typedef std::tuple<double, int> T;
  63. constexpr const T t(2.718, 5);
  64. static_assert(std::get<0>(std::move(t)) == 2.718, "");
  65. static_assert(std::get<1>(std::move(t)) == 5, "");
  66. }
  67. #endif
  68. return 0;
  69. }