]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc
158d132d6ef1522e1c2141bef1fda79db36b7e32
1 // { dg-options "-std=gnu++17" }
2 // { dg-do compile { target c++17 } }
4 // Copyright (C) 2017-2018 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/>.
23 template<typename T
, typename U
> struct require_same
;
24 template<typename T
> struct require_same
<T
, T
> { using type
= void; };
26 template<typename T
, typename U
>
27 typename require_same
<T
, U
>::type
34 MoveOnly
& operator=(MoveOnly
&&);
41 check_type
<std::tuple
<>>(x
);
44 check_type
<decltype(x
)>(copy
);
45 std::tuple move
= std::move(x
);
46 check_type
<decltype(x
)>(move
);
53 check_type
<std::tuple
<int>>(x
);
56 check_type
<std::tuple
<int>>(x2
);
59 check_type
<std::tuple
<int>>(x3
);
60 std::tuple mo
= MoveOnly();
61 check_type
<std::tuple
<MoveOnly
>>(mo
);
65 check_type
<decltype(x
)>(copy
);
66 std::tuple move
= std::move(mo
);
67 check_type
<decltype(mo
)>(move
);
74 check_type
<std::tuple
<int, unsigned>>(x
);
76 std::tuple x2
{y
, 48u};
77 check_type
<std::tuple
<int, unsigned>>(x2
);
80 check_type
<std::tuple
<int, int>>(x3
);
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};
88 check_type
<decltype(x
)>(copy
);
90 check_type
<decltype(x
)>(copy2
);
91 std::tuple move
= std::move(mo
);
92 check_type
<decltype(mo
)>(move
);
98 std::tuple x
{5, 6u, '7'};
99 check_type
<std::tuple
<int, unsigned, char>>(x
);
101 std::tuple x2
{y
, 48u, 54l};
102 check_type
<std::tuple
<int, unsigned, long>>(x2
);
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};
113 check_type
<decltype(x
)>(copy
);
115 check_type
<decltype(x
)>(copy2
);
116 std::tuple move
= std::move(mo
);
117 check_type
<decltype(mo
)>(move
);
123 std::pair
<int, unsigned> p
;
125 check_type
<std::tuple
<int, unsigned>>(x
);
128 check_type
<std::tuple
<int, unsigned>>(x2
);
130 std::pair
<const int, unsigned> p2
;
132 check_type
<std::tuple
<const int, unsigned>>(x3
);
133 std::pair
<int&, const unsigned&> p3
{p
.first
, p
.second
};
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
);
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
);
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
);
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
);
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
);