tuple.include.array.pass.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // struct tuple_element<I, tuple<Types...> >
  12. // {
  13. // typedef Ti type;
  14. // };
  15. //
  16. // LWG #2212 says that tuple_size and tuple_element must be
  17. // available after including <utility>
  18. #include <array>
  19. #include <type_traits>
  20. #include "test_macros.h"
  21. template <class T, std::size_t N, class U, size_t idx>
  22. void test()
  23. {
  24. static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
  25. std::tuple_size<T> >::value), "");
  26. static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
  27. std::tuple_size<const T> >::value), "");
  28. static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
  29. std::tuple_size<volatile T> >::value), "");
  30. static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
  31. std::tuple_size<const volatile T> >::value), "");
  32. static_assert((std::is_same<typename std::tuple_element<idx, T>::type, U>::value), "");
  33. static_assert((std::is_same<typename std::tuple_element<idx, const T>::type, const U>::value), "");
  34. static_assert((std::is_same<typename std::tuple_element<idx, volatile T>::type, volatile U>::value), "");
  35. static_assert((std::is_same<typename std::tuple_element<idx, const volatile T>::type, const volatile U>::value), "");
  36. }
  37. int main(int, char**)
  38. {
  39. test<std::array<int, 5>, 5, int, 0>();
  40. test<std::array<int, 5>, 5, int, 1>();
  41. test<std::array<const char *, 4>, 4, const char *, 3>();
  42. test<std::array<volatile int, 4>, 4, volatile int, 3>();
  43. test<std::array<char *, 3>, 3, char *, 1>();
  44. test<std::array<char *, 3>, 3, char *, 2>();
  45. return 0;
  46. }