tuple_element.pass.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // UNSUPPORTED: c++98, c++03
  18. #include <tuple>
  19. #include <type_traits>
  20. #include "test_macros.h"
  21. template <class T, std::size_t N, class U>
  22. void test()
  23. {
  24. static_assert((std::is_same<typename std::tuple_element<N, T>::type, U>::value), "");
  25. static_assert((std::is_same<typename std::tuple_element<N, const T>::type, const U>::value), "");
  26. static_assert((std::is_same<typename std::tuple_element<N, volatile T>::type, volatile U>::value), "");
  27. static_assert((std::is_same<typename std::tuple_element<N, const volatile T>::type, const volatile U>::value), "");
  28. #if TEST_STD_VER > 11
  29. static_assert((std::is_same<typename std::tuple_element_t<N, T>, U>::value), "");
  30. static_assert((std::is_same<typename std::tuple_element_t<N, const T>, const U>::value), "");
  31. static_assert((std::is_same<typename std::tuple_element_t<N, volatile T>, volatile U>::value), "");
  32. static_assert((std::is_same<typename std::tuple_element_t<N, const volatile T>, const volatile U>::value), "");
  33. #endif
  34. }
  35. int main()
  36. {
  37. test<std::tuple<int>, 0, int>();
  38. test<std::tuple<char, int>, 0, char>();
  39. test<std::tuple<char, int>, 1, int>();
  40. test<std::tuple<int*, char, int>, 0, int*>();
  41. test<std::tuple<int*, char, int>, 1, char>();
  42. test<std::tuple<int*, char, int>, 2, int>();
  43. }