tuple.include.array.pass.cpp 2.1 KB

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