get_const_rv.pass.cpp 2.5 KB

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