]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc
1 // { dg-options "-std=gnu++17" }
2 // { dg-do compile { target c++17 } }
4 // Copyright (C) 2017-2019 Free Software Foundation, Inc.
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)
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.
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/>.
24 template<typename T
, typename U
> struct require_same
;
25 template<typename T
> struct require_same
<T
, T
> { using type
= void; };
27 template<typename T
, typename U
>
28 typename require_same
<T
, U
>::type
35 MoveOnly
& operator=(MoveOnly
&&);
42 check_type
<std::tuple
<>>(x
);
45 check_type
<decltype(x
)>(copy
);
46 std::tuple move
= std::move(x
);
47 check_type
<decltype(x
)>(move
);
54 check_type
<std::tuple
<int>>(x
);
57 check_type
<std::tuple
<int>>(x2
);
60 check_type
<std::tuple
<int>>(x3
);
61 std::tuple mo
= MoveOnly();
62 check_type
<std::tuple
<MoveOnly
>>(mo
);
66 check_type
<decltype(x
)>(copy
);
67 std::tuple move
= std::move(mo
);
68 check_type
<decltype(mo
)>(move
);
75 check_type
<std::tuple
<int, unsigned>>(x
);
77 std::tuple x2
{y
, 48u};
78 check_type
<std::tuple
<int, unsigned>>(x2
);
81 check_type
<std::tuple
<int, int>>(x3
);
83 check_type
<std::tuple
<int, decltype(x
)>>(x4
);
84 std::tuple mo
{MoveOnly(), 2l};
85 check_type
<std::tuple
<MoveOnly
, long>>(mo
);
86 mo
= {MoveOnly(), 3l};
89 check_type
<decltype(x
)>(copy
);
91 check_type
<decltype(x
)>(copy2
);
92 std::tuple move
= std::move(mo
);
93 check_type
<decltype(mo
)>(move
);
99 std::tuple x
{5, 6u, '7'};
100 check_type
<std::tuple
<int, unsigned, char>>(x
);
102 std::tuple x2
{y
, 48u, 54l};
103 check_type
<std::tuple
<int, unsigned, long>>(x2
);
105 std::tuple x3
{z
, y
, x
};
106 check_type
<std::tuple
<int, int, decltype(x
)>>(x3
);
107 std::tuple x4
{1, x
, x2
};
108 check_type
<std::tuple
<int, decltype(x
), decltype(x2
)>>(x4
);
109 std::tuple mo
{MoveOnly(), 2l};
110 check_type
<std::tuple
<MoveOnly
, long>>(mo
);
111 mo
= {MoveOnly(), 3l};
114 check_type
<decltype(x
)>(copy
);
116 check_type
<decltype(x
)>(copy2
);
117 std::tuple move
= std::move(mo
);
118 check_type
<decltype(mo
)>(move
);
124 std::pair
<int, unsigned> p
;
126 check_type
<std::tuple
<int, unsigned>>(x
);
129 check_type
<std::tuple
<int, unsigned>>(x2
);
131 std::pair
<const int, unsigned> p2
;
133 check_type
<std::tuple
<const int, unsigned>>(x3
);
134 std::pair
<int&, const unsigned&> p3
{p
.first
, p
.second
};
136 check_type
<std::tuple
<int&, const unsigned&>>(x4
);
137 std::tuple mo
= std::pair
<MoveOnly
, MoveOnly
>();
138 check_type
<std::tuple
<MoveOnly
, MoveOnly
>>(mo
);
140 std::tuple copy
= x4
;
141 check_type
<decltype(x4
)>(copy
);
142 std::tuple copy2
{x4
};
143 check_type
<decltype(x4
)>(copy2
);
144 std::tuple move
= std::move(mo
);
145 check_type
<decltype(mo
)>(move
);
151 std::allocator
<double> a
;
152 std::tuple x
{std::allocator_arg
, a
, 1};
153 check_type
<std::tuple
<int>>(x
);
154 std::tuple x2
{std::allocator_arg
, a
, 1, '2'};
155 check_type
<std::tuple
<int, char>>(x2
);
157 std::pair
<float, const short> p
{};
158 std::tuple x3
{std::allocator_arg
, a
, p
};
159 check_type
<std::tuple
<float, const short>>(x3
);
160 std::tuple x4
{std::allocator_arg
, a
, std::move(p
)};
161 check_type
<std::tuple
<float, const short>>(x4
);
163 std::tuple x5
{std::allocator_arg
, a
, x
};
164 check_type
<decltype(x
)>(x5
);
165 std::tuple x6
{std::allocator_arg
, a
, std::move(x
)};
166 check_type
<decltype(x
)>(x6
);