| 1 | // { dg-do compile { target c++11 } } |
| 2 | |
| 3 | // Copyright (C) 2011-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 | |
| 21 | // NOTE: This makes use of the fact that we know how moveable |
| 22 | // is implemented on pair, and also vector. If the implementation |
| 23 | // changes this test may begin to fail. |
| 24 | |
| 25 | #include <tuple> |
| 26 | |
| 27 | // make_tuple |
| 28 | void |
| 29 | test_make_tuple() |
| 30 | { |
| 31 | { |
| 32 | typedef std::tuple<int, float> tuple_type; |
| 33 | constexpr tuple_type p1 __attribute__((unused)) |
| 34 | = std::make_tuple(22, 22.222); |
| 35 | } |
| 36 | |
| 37 | { |
| 38 | typedef std::tuple<int, float, int> tuple_type; |
| 39 | constexpr tuple_type p1 __attribute__((unused)) |
| 40 | = std::make_tuple(22, 22.222, 77799); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // forward_as_tuple |
| 45 | void |
| 46 | test_forward_as_tuple() |
| 47 | { |
| 48 | { |
| 49 | static int i(22); |
| 50 | static float f(22.222); |
| 51 | typedef std::tuple<int&, float&&> tuple_type; |
| 52 | constexpr tuple_type p1 __attribute__((unused)) |
| 53 | = std::forward_as_tuple(i, std::move(f)); |
| 54 | } |
| 55 | |
| 56 | { |
| 57 | static int i(22); |
| 58 | static float f(22.222); |
| 59 | static int ii(77799); |
| 60 | |
| 61 | typedef std::tuple<int&, float&, int&&> tuple_type; |
| 62 | constexpr tuple_type p1 __attribute__((unused)) |
| 63 | = std::forward_as_tuple(i, f, std::move(ii)); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // tie |
| 68 | void |
| 69 | test_tie() |
| 70 | { |
| 71 | { |
| 72 | static int i(22); |
| 73 | static float f(22.222); |
| 74 | typedef std::tuple<int&, float&> tuple_type; |
| 75 | constexpr tuple_type p1 __attribute__((unused)) |
| 76 | = std::tie(i, f); |
| 77 | } |
| 78 | |
| 79 | { |
| 80 | static int i(22); |
| 81 | static float f(22.222); |
| 82 | static const int ii(77799); |
| 83 | |
| 84 | typedef std::tuple<int&, float&, const int&> tuple_type; |
| 85 | constexpr tuple_type p1 __attribute__((unused)) |
| 86 | = std::tie(i, f, ii); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // get |
| 91 | void |
| 92 | test_get() |
| 93 | { |
| 94 | { |
| 95 | typedef std::tuple<int, float> tuple_type; |
| 96 | constexpr tuple_type t1 { 55, 77.77 }; |
| 97 | constexpr auto var __attribute__((unused)) |
| 98 | = std::get<1>(t1); |
| 99 | } |
| 100 | |
| 101 | { |
| 102 | typedef std::tuple<int, float, int> tuple_type; |
| 103 | constexpr tuple_type t1 { 55, 77.77, 99 }; |
| 104 | constexpr auto var __attribute__((unused)) |
| 105 | = std::get<2>(t1); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // tuple_cat |
| 110 | void |
| 111 | test_tuple_cat() |
| 112 | { |
| 113 | typedef std::tuple<int, float> tuple_type1; |
| 114 | typedef std::tuple<int, int, float> tuple_type2; |
| 115 | |
| 116 | constexpr tuple_type1 t1 { 55, 77.77 }; |
| 117 | constexpr tuple_type2 t2 { 55, 99, 77.77 }; |
| 118 | constexpr auto cat1 __attribute__((unused)) = std::tuple_cat(t1, t2); |
| 119 | } |
| 120 | |
| 121 | namespace { |
| 122 | |
| 123 | template<class T> |
| 124 | constexpr int zero_from_anything(T) |
| 125 | { |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | } |
| 130 | |
| 131 | // ignore, see LWG 2773 |
| 132 | void |
| 133 | test_ignore() |
| 134 | { |
| 135 | constexpr auto ign1 __attribute__((unused)) = std::ignore; |
| 136 | constexpr auto ign2 __attribute__((unused)) = std::make_tuple(std::ignore); |
| 137 | constexpr int ign3 __attribute__((unused)) = zero_from_anything(std::ignore); |
| 138 | } |
| 139 | |
| 140 | int |
| 141 | main() |
| 142 | { |
| 143 | test_make_tuple(); |
| 144 | test_forward_as_tuple(); |
| 145 | test_tie(); |
| 146 | test_get(); |
| 147 | test_tuple_cat(); |
| 148 | test_ignore(); |
| 149 | |
| 150 | return 0; |
| 151 | } |