]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do compile { target c++11 } } |
a7d0c94e | 2 | |
a5544970 | 3 | // Copyright (C) 2011-2019 Free Software Foundation, Inc. |
a7d0c94e BK |
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 | ||
a7d0c94e | 27 | // make_tuple |
a7d0c94e BK |
28 | void |
29 | test_make_tuple() | |
30 | { | |
31 | { | |
32 | typedef std::tuple<int, float> tuple_type; | |
71743a68 PC |
33 | constexpr tuple_type p1 __attribute__((unused)) |
34 | = std::make_tuple(22, 22.222); | |
a7d0c94e BK |
35 | } |
36 | ||
37 | { | |
38 | typedef std::tuple<int, float, int> tuple_type; | |
71743a68 PC |
39 | constexpr tuple_type p1 __attribute__((unused)) |
40 | = std::make_tuple(22, 22.222, 77799); | |
a7d0c94e BK |
41 | } |
42 | } | |
a7d0c94e | 43 | |
a9ba8ba5 BK |
44 | // forward_as_tuple |
45 | void | |
46 | test_forward_as_tuple() | |
47 | { | |
48 | { | |
cb2ef49e JW |
49 | static int i(22); |
50 | static float f(22.222); | |
51 | typedef std::tuple<int&, float&&> tuple_type; | |
a9ba8ba5 | 52 | constexpr tuple_type p1 __attribute__((unused)) |
cb2ef49e | 53 | = std::forward_as_tuple(i, std::move(f)); |
a9ba8ba5 BK |
54 | } |
55 | ||
56 | { | |
cb2ef49e JW |
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; | |
a9ba8ba5 | 62 | constexpr tuple_type p1 __attribute__((unused)) |
cb2ef49e | 63 | = std::forward_as_tuple(i, f, std::move(ii)); |
a9ba8ba5 BK |
64 | } |
65 | } | |
a9ba8ba5 | 66 | |
a9ba8ba5 BK |
67 | // tie |
68 | void | |
69 | test_tie() | |
70 | { | |
71 | { | |
cb2ef49e JW |
72 | static int i(22); |
73 | static float f(22.222); | |
74 | typedef std::tuple<int&, float&> tuple_type; | |
a9ba8ba5 BK |
75 | constexpr tuple_type p1 __attribute__((unused)) |
76 | = std::tie(i, f); | |
77 | } | |
78 | ||
79 | { | |
cb2ef49e JW |
80 | static int i(22); |
81 | static float f(22.222); | |
82 | static const int ii(77799); | |
a9ba8ba5 | 83 | |
cb2ef49e | 84 | typedef std::tuple<int&, float&, const int&> tuple_type; |
a9ba8ba5 BK |
85 | constexpr tuple_type p1 __attribute__((unused)) |
86 | = std::tie(i, f, ii); | |
87 | } | |
88 | } | |
a9ba8ba5 | 89 | |
a7d0c94e BK |
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 }; | |
71743a68 PC |
97 | constexpr auto var __attribute__((unused)) |
98 | = std::get<1>(t1); | |
a7d0c94e BK |
99 | } |
100 | ||
101 | { | |
102 | typedef std::tuple<int, float, int> tuple_type; | |
103 | constexpr tuple_type t1 { 55, 77.77, 99 }; | |
71743a68 PC |
104 | constexpr auto var __attribute__((unused)) |
105 | = std::get<2>(t1); | |
a7d0c94e BK |
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 }; | |
71743a68 | 118 | constexpr auto cat1 __attribute__((unused)) = std::tuple_cat(t1, t2); |
a7d0c94e | 119 | } |
a7d0c94e | 120 | |
288695f7 DK |
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 | ||
a7d0c94e BK |
140 | int |
141 | main() | |
142 | { | |
a7d0c94e | 143 | test_make_tuple(); |
cb2ef49e JW |
144 | test_forward_as_tuple(); |
145 | test_tie(); | |
a7d0c94e | 146 | test_get(); |
a7d0c94e | 147 | test_tuple_cat(); |
288695f7 | 148 | test_ignore(); |
a7d0c94e BK |
149 | |
150 | return 0; | |
151 | } |