tuple.include.utility.pass.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include "test_macros.h"
  20. template <class T, std::size_t N, class U, size_t idx>
  21. void test()
  22. {
  23. static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
  24. std::tuple_size<T> >::value), "");
  25. static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
  26. std::tuple_size<const T> >::value), "");
  27. static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
  28. std::tuple_size<volatile T> >::value), "");
  29. static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
  30. std::tuple_size<const volatile T> >::value), "");
  31. static_assert((std::is_same<typename std::tuple_element<idx, T>::type, U>::value), "");
  32. static_assert((std::is_same<typename std::tuple_element<idx, const T>::type, const U>::value), "");
  33. static_assert((std::is_same<typename std::tuple_element<idx, volatile T>::type, volatile U>::value), "");
  34. static_assert((std::is_same<typename std::tuple_element<idx, const volatile T>::type, const volatile U>::value), "");
  35. }
  36. int main(int, char**)
  37. {
  38. test<std::pair<int, int>, 2, int, 0>();
  39. test<std::pair<int, int>, 2, int, 1>();
  40. test<std::pair<const int, int>, 2, int, 1>();
  41. test<std::pair<int, volatile int>, 2, volatile int, 1>();
  42. test<std::pair<char *, int>, 2, char *, 0>();
  43. test<std::pair<char *, int>, 2, int, 1>();
  44. return 0;
  45. }