tuple_like.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2020-2022 Free Software Foundation, Inc.
  2. //
  3. // This file is part of the GNU ISO C++ Library. This library is free
  4. // software; you can redistribute it and/or modify it under the
  5. // terms of the GNU General Public License as published by the
  6. // Free Software Foundation; either version 3, or (at your option)
  7. // any later version.
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License along
  13. // with this library; see the file COPYING3. If not see
  14. // <http://www.gnu.org/licenses/>.
  15. // { dg-options "-std=gnu++2a" }
  16. // { dg-do compile { target c++2a } }
  17. #include <ranges>
  18. using S1 = std::ranges::subrange<int*>;
  19. using S2 = std::ranges::subrange<long*, void*>;
  20. static_assert( std::tuple_size_v<S1> == 2 );
  21. static_assert( std::tuple_size_v<S2> == 2 );
  22. static_assert( std::same_as<std::tuple_element_t<0, S1>, int*> );
  23. static_assert( std::same_as<std::tuple_element_t<1, S1>, int*> );
  24. // LWG 3398
  25. static_assert( std::same_as<std::tuple_element_t<0, const S1>, int*> );
  26. static_assert( std::same_as<std::tuple_element_t<1, const S1>, int*> );
  27. static_assert( std::same_as<std::tuple_element_t<0, S2>, long*> );
  28. static_assert( std::same_as<std::tuple_element_t<1, S2>, void*> );
  29. // LWG 3398
  30. static_assert( std::same_as<std::tuple_element_t<0, const S2>, long*> );
  31. static_assert( std::same_as<std::tuple_element_t<1, const S2>, void*> );
  32. S1 s1;
  33. static_assert( std::same_as<decltype(std::get<0>(s1)), int*> );
  34. static_assert( std::same_as<decltype(std::get<1>(s1)), int*> );
  35. const S1 c1;
  36. static_assert( std::same_as<decltype(std::get<0>(c1)), int*> );
  37. static_assert( std::same_as<decltype(std::get<1>(c1)), int*> );
  38. S2 s2;
  39. static_assert( std::same_as<decltype(std::get<0>(s2)), long*> );
  40. static_assert( std::same_as<decltype(std::get<1>(s2)), void*> );
  41. const S2 c2;
  42. static_assert( std::same_as<decltype(std::get<0>(c2)), long*> );
  43. static_assert( std::same_as<decltype(std::get<1>(c2)), void*> );