tuple.include.utility.pass.cpp 2.1 KB

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