| 1 | // { dg-do run { target c++11 } } |
| 2 | |
| 3 | // 2010-04-30 Paolo Carlini <[email protected]> |
| 4 | // |
| 5 | // Copyright (C) 2010-2025 Free Software Foundation, Inc. |
| 6 | // |
| 7 | // This file is part of the GNU ISO C++ Library. This library is free |
| 8 | // software; you can redistribute it and/or modify it under the |
| 9 | // terms of the GNU General Public License as published by the |
| 10 | // Free Software Foundation; either version 3, or (at your option) |
| 11 | // any later version. |
| 12 | |
| 13 | // This library is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | |
| 18 | // You should have received a copy of the GNU General Public License along |
| 19 | // with this library; see the file COPYING3. If not see |
| 20 | // <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | // Tuple |
| 23 | |
| 24 | #include <tuple> |
| 25 | #include <type_traits> |
| 26 | #include <testsuite_hooks.h> |
| 27 | |
| 28 | void |
| 29 | test01() |
| 30 | { |
| 31 | std::forward_as_tuple(); |
| 32 | |
| 33 | VERIFY( std::get<0>(std::forward_as_tuple(-1)) == -1 ); |
| 34 | VERIFY( (std::is_same<decltype(std::forward_as_tuple(-1)), |
| 35 | std::tuple<int&&>>::value) ); |
| 36 | |
| 37 | const int i1 = 1; |
| 38 | const int i2 = 2; |
| 39 | const double d1 = 4.0; |
| 40 | auto t1 = std::forward_as_tuple(i1, i2, d1); |
| 41 | VERIFY( (std::is_same<decltype(t1), std::tuple<const int&, |
| 42 | const int&, const double&>>::value) ); |
| 43 | VERIFY( std::get<0>(t1) == i1 ); |
| 44 | VERIFY( std::get<1>(t1) == i2 ); |
| 45 | VERIFY( std::get<2>(t1) == d1 ); |
| 46 | |
| 47 | typedef const int a_type1[3]; |
| 48 | a_type1 a1 = { -1, 1, 2 }; |
| 49 | auto t2 = std::forward_as_tuple(a1); |
| 50 | VERIFY( (std::is_same<decltype(t2), std::tuple<a_type1&>>::value) ); |
| 51 | VERIFY( std::get<0>(t2)[0] == a1[0] ); |
| 52 | VERIFY( std::get<0>(t2)[1] == a1[1] ); |
| 53 | VERIFY( std::get<0>(t2)[2] == a1[2] ); |
| 54 | |
| 55 | typedef int a_type2[2]; |
| 56 | a_type2 a2 = { 2, -2 }; |
| 57 | volatile int i4 = 1; |
| 58 | auto t3 = std::forward_as_tuple(a2, i4); |
| 59 | VERIFY( (std::is_same<decltype(t3), std::tuple<a_type2&, |
| 60 | volatile int&>>::value) ); |
| 61 | VERIFY( std::get<0>(t3)[0] == a2[0] ); |
| 62 | VERIFY( std::get<0>(t3)[1] == a2[1] ); |
| 63 | VERIFY( std::get<1>(t3) == i4 ); |
| 64 | } |
| 65 | |
| 66 | int main() |
| 67 | { |
| 68 | test01(); |
| 69 | return 0; |
| 70 | } |