| 1 | // { dg-do compile { target c++11 } } |
| 2 | |
| 3 | // Copyright (C) 2013-2025 Free Software Foundation, Inc. |
| 4 | // |
| 5 | // This file is part of the GNU ISO C++ Library. This library is free |
| 6 | // software; you can redistribute it and/or modify it under the |
| 7 | // terms of the GNU General Public License as published by the |
| 8 | // Free Software Foundation; either version 3, or (at your option) |
| 9 | // any later version. |
| 10 | // |
| 11 | // This library is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | // |
| 16 | // You should have received a copy of the GNU General Public License along |
| 17 | // with this library; see the file COPYING3. If not see |
| 18 | // <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | // NB: Don't include any other headers in this file. |
| 21 | // LWG 2212 requires <utility> to define tuple_size<cv T> and |
| 22 | // tuple_element<cv T> specializations. |
| 23 | #include <utility> |
| 24 | |
| 25 | typedef std::pair<int, long> test_type; |
| 26 | |
| 27 | static_assert( std::tuple_size<test_type>::value == 2, "size is 2" ); |
| 28 | static_assert( std::tuple_size<const test_type>::value == 2, "size is 2" ); |
| 29 | static_assert( std::tuple_size<volatile test_type>::value == 2, "size is 2" ); |
| 30 | static_assert( std::tuple_size<const volatile test_type>::value == 2, |
| 31 | "size is 2" ); |
| 32 | |
| 33 | template<std::size_t N, typename T> |
| 34 | using Tuple_elt = typename std::tuple_element<N, T>::type; |
| 35 | |
| 36 | // This relies on the fact that <utility> includes <type_traits>: |
| 37 | using std::is_same; |
| 38 | |
| 39 | static_assert( is_same<Tuple_elt<0, test_type>, test_type::first_type>::value, |
| 40 | "first type is int" ); |
| 41 | |
| 42 | static_assert( is_same<Tuple_elt<1, test_type>, test_type::second_type>::value, |
| 43 | "second type is long" ); |
| 44 | |
| 45 | static_assert( is_same<Tuple_elt<0, const test_type>, |
| 46 | const test_type::first_type>::value, |
| 47 | "first type is const int" ); |
| 48 | |
| 49 | static_assert( is_same<Tuple_elt<1, const test_type>, |
| 50 | const test_type::second_type>::value, |
| 51 | "second type is const long" ); |
| 52 | |
| 53 | static_assert( is_same<Tuple_elt<0, volatile test_type>, |
| 54 | volatile test_type::first_type>::value, |
| 55 | "first type is volatile int" ); |
| 56 | |
| 57 | static_assert( is_same<Tuple_elt<1, volatile test_type>, |
| 58 | volatile test_type::second_type>::value, |
| 59 | "second type is volatile long" ); |
| 60 | |
| 61 | static_assert( is_same<Tuple_elt<0, const volatile test_type>, |
| 62 | const volatile test_type::first_type>::value, |
| 63 | "first type is const volatile int" ); |
| 64 | |
| 65 | static_assert( is_same<Tuple_elt<1, const volatile test_type>, |
| 66 | const volatile test_type::second_type>::value, |
| 67 | "second type is const volatile long" ); |