get_const_rv.pass.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // <array>
  10. // template <size_t I, class T, size_t N> const T&& get(const array<T, N>&& a);
  11. // UNSUPPORTED: c++98, c++03
  12. #include <array>
  13. #include <memory>
  14. #include <type_traits>
  15. #include <utility>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. // std::array is explicitly allowed to be initialized with A a = { init-list };.
  19. // Disable the missing braces warning for this reason.
  20. #include "disable_missing_braces_warning.h"
  21. int main()
  22. {
  23. {
  24. typedef std::unique_ptr<double> T;
  25. typedef std::array<T, 1> C;
  26. const C c = {std::unique_ptr<double>(new double(3.5))};
  27. static_assert(std::is_same<const T&&, decltype(std::get<0>(std::move(c)))>::value, "");
  28. static_assert(noexcept(std::get<0>(std::move(c))), "");
  29. const T&& t = std::get<0>(std::move(c));
  30. assert(*t == 3.5);
  31. }
  32. #if TEST_STD_VER > 11
  33. {
  34. typedef double T;
  35. typedef std::array<T, 3> C;
  36. constexpr const C c = {1, 2, 3.5};
  37. static_assert(std::get<0>(std::move(c)) == 1, "");
  38. static_assert(std::get<1>(std::move(c)) == 2, "");
  39. static_assert(std::get<2>(std::move(c)) == 3.5, "");
  40. }
  41. #endif
  42. }