tuple.include.utility.pass.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 <class... Types>
  12. // class tuple_size<tuple<Types...>>
  13. // : public integral_constant<size_t, sizeof...(Types)> { };
  14. //
  15. // LWG #2212 says that tuple_size and tuple_element must be
  16. // available after including <utility>
  17. #include <cstddef>
  18. #include <utility>
  19. #include <type_traits>
  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()
  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. }