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