get_const_rv.pass.cpp 1.5 KB

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