]>
Commit | Line | Data |
---|---|---|
af181c91 | 1 | // { dg-options "-std=gnu++17" } |
7b936140 | 2 | // { dg-do compile { target c++17 } } |
af181c91 | 3 | |
85ec4feb | 4 | // Copyright (C) 2017-2018 Free Software Foundation, Inc. |
af181c91 JW |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING3. If not see | |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | #include <tuple> | |
22 | ||
23 | template<typename T, typename U> struct require_same; | |
24 | template<typename T> struct require_same<T, T> { using type = void; }; | |
25 | ||
26 | template<typename T, typename U> | |
27 | typename require_same<T, U>::type | |
28 | check_type(U&) { } | |
29 | ||
30 | struct MoveOnly | |
31 | { | |
32 | MoveOnly() = default; | |
98910bc2 PC |
33 | MoveOnly(MoveOnly&&); |
34 | MoveOnly& operator=(MoveOnly&&); | |
af181c91 JW |
35 | }; |
36 | ||
37 | void | |
38 | test00() | |
39 | { | |
40 | std::tuple x; | |
41 | check_type<std::tuple<>>(x); | |
42 | ||
43 | std::tuple copy = x; | |
44 | check_type<decltype(x)>(copy); | |
45 | std::tuple move = std::move(x); | |
46 | check_type<decltype(x)>(move); | |
47 | } | |
48 | ||
49 | void | |
50 | test01() | |
51 | { | |
52 | std::tuple x = 5; | |
53 | check_type<std::tuple<int>>(x); | |
54 | int y = 42; | |
55 | std::tuple x2 = y; | |
56 | check_type<std::tuple<int>>(x2); | |
57 | const int z = 666; | |
58 | std::tuple x3 = z; | |
59 | check_type<std::tuple<int>>(x3); | |
60 | std::tuple mo = MoveOnly(); | |
61 | check_type<std::tuple<MoveOnly>>(mo); | |
62 | mo = MoveOnly(); | |
63 | ||
64 | std::tuple copy = x; | |
65 | check_type<decltype(x)>(copy); | |
66 | std::tuple move = std::move(mo); | |
67 | check_type<decltype(mo)>(move); | |
68 | } | |
69 | ||
70 | void | |
71 | test02() | |
72 | { | |
73 | std::tuple x{5, 6u}; | |
74 | check_type<std::tuple<int, unsigned>>(x); | |
75 | int y = 42; | |
76 | std::tuple x2{y, 48u}; | |
77 | check_type<std::tuple<int, unsigned>>(x2); | |
78 | const int z = 666; | |
79 | std::tuple x3{z, y}; | |
80 | check_type<std::tuple<int, int>>(x3); | |
81 | std::tuple x4{1, x}; | |
82 | check_type<std::tuple<int, decltype(x)>>(x4); | |
83 | std::tuple mo{MoveOnly(), 2l}; | |
84 | check_type<std::tuple<MoveOnly, long>>(mo); | |
85 | mo = {MoveOnly(), 3l}; | |
86 | ||
87 | std::tuple copy = x; | |
88 | check_type<decltype(x)>(copy); | |
89 | std::tuple copy2{x}; | |
90 | check_type<decltype(x)>(copy2); | |
91 | std::tuple move = std::move(mo); | |
92 | check_type<decltype(mo)>(move); | |
93 | } | |
94 | ||
95 | void | |
96 | test03() | |
97 | { | |
98 | std::tuple x{5, 6u, '7'}; | |
99 | check_type<std::tuple<int, unsigned, char>>(x); | |
100 | int y = 42; | |
101 | std::tuple x2{y, 48u, 54l}; | |
102 | check_type<std::tuple<int, unsigned, long>>(x2); | |
103 | const int z = 666; | |
104 | std::tuple x3{z, y, x}; | |
105 | check_type<std::tuple<int, int, decltype(x)>>(x3); | |
106 | std::tuple x4{1, x, x2}; | |
107 | check_type<std::tuple<int, decltype(x), decltype(x2)>>(x4); | |
108 | std::tuple mo{MoveOnly(), 2l}; | |
109 | check_type<std::tuple<MoveOnly, long>>(mo); | |
110 | mo = {MoveOnly(), 3l}; | |
111 | ||
112 | std::tuple copy = x; | |
113 | check_type<decltype(x)>(copy); | |
114 | std::tuple copy2{x}; | |
115 | check_type<decltype(x)>(copy2); | |
116 | std::tuple move = std::move(mo); | |
117 | check_type<decltype(mo)>(move); | |
118 | } | |
119 | ||
120 | void | |
121 | test04() | |
122 | { | |
123 | std::pair<int, unsigned> p; | |
124 | std::tuple x = p; | |
125 | check_type<std::tuple<int, unsigned>>(x); | |
126 | int y = 42; | |
127 | std::tuple x2{p}; | |
128 | check_type<std::tuple<int, unsigned>>(x2); | |
129 | const int z = 666; | |
130 | std::pair<const int, unsigned> p2; | |
131 | std::tuple x3{p2}; | |
132 | check_type<std::tuple<const int, unsigned>>(x3); | |
133 | std::pair<int&, const unsigned&> p3{p.first, p.second}; | |
134 | std::tuple x4{p3}; | |
135 | check_type<std::tuple<int&, const unsigned&>>(x4); | |
136 | std::tuple mo = std::pair<MoveOnly, MoveOnly>(); | |
137 | check_type<std::tuple<MoveOnly, MoveOnly>>(mo); | |
138 | ||
139 | std::tuple copy = x4; | |
140 | check_type<decltype(x4)>(copy); | |
141 | std::tuple copy2{x4}; | |
142 | check_type<decltype(x4)>(copy2); | |
143 | std::tuple move = std::move(mo); | |
144 | check_type<decltype(mo)>(move); | |
145 | } | |
146 | ||
147 | void | |
148 | test05() | |
149 | { | |
150 | std::allocator<double> a; | |
151 | std::tuple x{std::allocator_arg, a, 1}; | |
152 | check_type<std::tuple<int>>(x); | |
153 | std::tuple x2{std::allocator_arg, a, 1, '2'}; | |
154 | check_type<std::tuple<int, char>>(x2); | |
155 | ||
156 | std::pair<float, const short> p{}; | |
157 | std::tuple x3{std::allocator_arg, a, p}; | |
158 | check_type<std::tuple<float, const short>>(x3); | |
159 | std::tuple x4{std::allocator_arg, a, std::move(p)}; | |
160 | check_type<std::tuple<float, const short>>(x4); | |
161 | ||
162 | std::tuple x5{std::allocator_arg, a, x}; | |
163 | check_type<decltype(x)>(x5); | |
164 | std::tuple x6{std::allocator_arg, a, std::move(x)}; | |
165 | check_type<decltype(x)>(x6); | |
166 | } |