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