]>
Commit | Line | Data |
---|---|---|
af13a7a6 BK |
1 | // <tuple> -*- C++ -*- |
2 | ||
a5544970 | 3 | // Copyright (C) 2007-2019 Free Software Foundation, Inc. |
af13a7a6 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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
af13a7a6 BK |
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 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
af13a7a6 BK |
24 | |
25 | /** @file include/tuple | |
26 | * This is a Standard C++ Library header. | |
27 | */ | |
28 | ||
4514bed6 BK |
29 | #ifndef _GLIBCXX_TUPLE |
30 | #define _GLIBCXX_TUPLE 1 | |
af13a7a6 BK |
31 | |
32 | #pragma GCC system_header | |
33 | ||
734f5023 | 34 | #if __cplusplus < 201103L |
ab65a4c7 | 35 | # include <bits/c++0x_warning.h> |
57317d2a | 36 | #else |
af13a7a6 | 37 | |
e133ace8 | 38 | #include <utility> |
0611ce44 | 39 | #include <array> |
b8214660 | 40 | #include <bits/uses_allocator.h> |
3e9f67e6 | 41 | #include <bits/invoke.h> |
e133ace8 | 42 | |
12ffa228 BK |
43 | namespace std _GLIBCXX_VISIBILITY(default) |
44 | { | |
45 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
53dc5044 | 46 | |
c0ffa2ba BK |
47 | /** |
48 | * @addtogroup utilities | |
49 | * @{ | |
50 | */ | |
51 | ||
373c0095 FD |
52 | template<typename... _Elements> |
53 | class tuple; | |
54 | ||
55 | template<typename _Tp> | |
56 | struct __is_empty_non_tuple : is_empty<_Tp> { }; | |
57 | ||
58 | // Using EBO for elements that are tuples causes ambiguous base errors. | |
59 | template<typename _El0, typename... _El> | |
60 | struct __is_empty_non_tuple<tuple<_El0, _El...>> : false_type { }; | |
61 | ||
62 | // Use the Empty Base-class Optimization for empty, non-final types. | |
63 | template<typename _Tp> | |
64 | using __empty_not_final | |
65 | = typename conditional<__is_final(_Tp), false_type, | |
66 | __is_empty_non_tuple<_Tp>>::type; | |
67 | ||
68 | template<std::size_t _Idx, typename _Head, | |
69 | bool = __empty_not_final<_Head>::value> | |
ba60f6f9 PC |
70 | struct _Head_base; |
71 | ||
740508be | 72 | template<std::size_t _Idx, typename _Head> |
894d0b15 CF |
73 | struct _Head_base<_Idx, _Head, true> |
74 | : public _Head | |
75 | { | |
0e6ac87e | 76 | constexpr _Head_base() |
894d0b15 CF |
77 | : _Head() { } |
78 | ||
094a14ef | 79 | constexpr _Head_base(const _Head& __h) |
894d0b15 CF |
80 | : _Head(__h) { } |
81 | ||
f4081d13 JW |
82 | constexpr _Head_base(const _Head_base&) = default; |
83 | constexpr _Head_base(_Head_base&&) = default; | |
84 | ||
85 | template<typename _UHead> | |
2c4caf0a | 86 | constexpr _Head_base(_UHead&& __h) |
fe960d92 | 87 | : _Head(std::forward<_UHead>(__h)) { } |
894d0b15 | 88 | |
f4081d13 | 89 | _Head_base(allocator_arg_t, __uses_alloc0) |
b8214660 JW |
90 | : _Head() { } |
91 | ||
92 | template<typename _Alloc> | |
f4081d13 | 93 | _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a) |
b8214660 JW |
94 | : _Head(allocator_arg, *__a._M_a) { } |
95 | ||
96 | template<typename _Alloc> | |
f4081d13 | 97 | _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a) |
b8214660 JW |
98 | : _Head(*__a._M_a) { } |
99 | ||
100 | template<typename _UHead> | |
101 | _Head_base(__uses_alloc0, _UHead&& __uhead) | |
102 | : _Head(std::forward<_UHead>(__uhead)) { } | |
103 | ||
104 | template<typename _Alloc, typename _UHead> | |
105 | _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead) | |
106 | : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { } | |
107 | ||
108 | template<typename _Alloc, typename _UHead> | |
109 | _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead) | |
110 | : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { } | |
111 | ||
9480716c DK |
112 | static constexpr _Head& |
113 | _M_head(_Head_base& __b) noexcept { return __b; } | |
2c4caf0a | 114 | |
9480716c DK |
115 | static constexpr const _Head& |
116 | _M_head(const _Head_base& __b) noexcept { return __b; } | |
894d0b15 CF |
117 | }; |
118 | ||
740508be | 119 | template<std::size_t _Idx, typename _Head> |
894d0b15 CF |
120 | struct _Head_base<_Idx, _Head, false> |
121 | { | |
0e6ac87e | 122 | constexpr _Head_base() |
894d0b15 CF |
123 | : _M_head_impl() { } |
124 | ||
094a14ef | 125 | constexpr _Head_base(const _Head& __h) |
894d0b15 CF |
126 | : _M_head_impl(__h) { } |
127 | ||
f4081d13 JW |
128 | constexpr _Head_base(const _Head_base&) = default; |
129 | constexpr _Head_base(_Head_base&&) = default; | |
130 | ||
131 | template<typename _UHead> | |
2c4caf0a | 132 | constexpr _Head_base(_UHead&& __h) |
fe960d92 | 133 | : _M_head_impl(std::forward<_UHead>(__h)) { } |
894d0b15 | 134 | |
f4081d13 | 135 | _Head_base(allocator_arg_t, __uses_alloc0) |
b8214660 JW |
136 | : _M_head_impl() { } |
137 | ||
138 | template<typename _Alloc> | |
f4081d13 | 139 | _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a) |
b8214660 JW |
140 | : _M_head_impl(allocator_arg, *__a._M_a) { } |
141 | ||
142 | template<typename _Alloc> | |
f4081d13 | 143 | _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a) |
b8214660 JW |
144 | : _M_head_impl(*__a._M_a) { } |
145 | ||
146 | template<typename _UHead> | |
147 | _Head_base(__uses_alloc0, _UHead&& __uhead) | |
148 | : _M_head_impl(std::forward<_UHead>(__uhead)) { } | |
149 | ||
150 | template<typename _Alloc, typename _UHead> | |
151 | _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead) | |
152 | : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) | |
153 | { } | |
154 | ||
155 | template<typename _Alloc, typename _UHead> | |
156 | _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead) | |
157 | : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { } | |
158 | ||
9480716c DK |
159 | static constexpr _Head& |
160 | _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; } | |
2c4caf0a | 161 | |
9480716c DK |
162 | static constexpr const _Head& |
163 | _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; } | |
894d0b15 | 164 | |
9480716c | 165 | _Head _M_head_impl; |
894d0b15 CF |
166 | }; |
167 | ||
168 | /** | |
894d0b15 CF |
169 | * Contains the actual implementation of the @c tuple template, stored |
170 | * as a recursive inheritance hierarchy from the first element (most | |
171 | * derived class) to the last (least derived class). The @c Idx | |
172 | * parameter gives the 0-based index of the element stored at this | |
173 | * point in the hierarchy; we use it to implement a constant-time | |
174 | * get() operation. | |
894d0b15 | 175 | */ |
740508be | 176 | template<std::size_t _Idx, typename... _Elements> |
33ac58d5 | 177 | struct _Tuple_impl; |
894d0b15 | 178 | |
894d0b15 | 179 | /** |
894d0b15 CF |
180 | * Recursive tuple implementation. Here we store the @c Head element |
181 | * and derive from a @c Tuple_impl containing the remaining elements | |
182 | * (which contains the @c Tail). | |
894d0b15 | 183 | */ |
740508be | 184 | template<std::size_t _Idx, typename _Head, typename... _Tail> |
894d0b15 CF |
185 | struct _Tuple_impl<_Idx, _Head, _Tail...> |
186 | : public _Tuple_impl<_Idx + 1, _Tail...>, | |
373c0095 | 187 | private _Head_base<_Idx, _Head> |
894d0b15 | 188 | { |
1aa1114b PC |
189 | template<std::size_t, typename...> friend class _Tuple_impl; |
190 | ||
894d0b15 | 191 | typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited; |
373c0095 | 192 | typedef _Head_base<_Idx, _Head> _Base; |
894d0b15 | 193 | |
33ac58d5 | 194 | static constexpr _Head& |
9480716c | 195 | _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); } |
2c4caf0a | 196 | |
9480716c DK |
197 | static constexpr const _Head& |
198 | _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); } | |
894d0b15 | 199 | |
9480716c DK |
200 | static constexpr _Inherited& |
201 | _M_tail(_Tuple_impl& __t) noexcept { return __t; } | |
2c4caf0a | 202 | |
9480716c DK |
203 | static constexpr const _Inherited& |
204 | _M_tail(const _Tuple_impl& __t) noexcept { return __t; } | |
894d0b15 | 205 | |
0e6ac87e | 206 | constexpr _Tuple_impl() |
894d0b15 CF |
207 | : _Inherited(), _Base() { } |
208 | ||
33ac58d5 | 209 | explicit |
094a14ef | 210 | constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail) |
894d0b15 CF |
211 | : _Inherited(__tail...), _Base(__head) { } |
212 | ||
b8214660 | 213 | template<typename _UHead, typename... _UTail, typename = typename |
33ac58d5 | 214 | enable_if<sizeof...(_Tail) == sizeof...(_UTail)>::type> |
ba60f6f9 | 215 | explicit |
2c4caf0a | 216 | constexpr _Tuple_impl(_UHead&& __head, _UTail&&... __tail) |
b5b5e640 PC |
217 | : _Inherited(std::forward<_UTail>(__tail)...), |
218 | _Base(std::forward<_UHead>(__head)) { } | |
894d0b15 | 219 | |
094a14ef | 220 | constexpr _Tuple_impl(const _Tuple_impl&) = default; |
894d0b15 | 221 | |
a2c5e1ae JW |
222 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
223 | // 2729. Missing SFINAE on std::pair::operator= | |
224 | _Tuple_impl& operator=(const _Tuple_impl&) = delete; | |
225 | ||
fae3f459 | 226 | constexpr |
3fe2ddae VV |
227 | _Tuple_impl(_Tuple_impl&& __in) |
228 | noexcept(__and_<is_nothrow_move_constructible<_Head>, | |
dd7b175e | 229 | is_nothrow_move_constructible<_Inherited>>::value) |
33ac58d5 | 230 | : _Inherited(std::move(_M_tail(__in))), |
9480716c | 231 | _Base(std::forward<_Head>(_M_head(__in))) { } |
ba60f6f9 | 232 | |
894d0b15 | 233 | template<typename... _UElements> |
a7d0c94e | 234 | constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in) |
9480716c DK |
235 | : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)), |
236 | _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { } | |
ba60f6f9 | 237 | |
78a869ec | 238 | template<typename _UHead, typename... _UTails> |
3fe2ddae | 239 | constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in) |
fae3f459 PC |
240 | : _Inherited(std::move |
241 | (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))), | |
9480716c DK |
242 | _Base(std::forward<_UHead> |
243 | (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { } | |
894d0b15 | 244 | |
b8214660 JW |
245 | template<typename _Alloc> |
246 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a) | |
247 | : _Inherited(__tag, __a), | |
f4081d13 | 248 | _Base(__tag, __use_alloc<_Head>(__a)) { } |
b8214660 JW |
249 | |
250 | template<typename _Alloc> | |
251 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
dd7b175e | 252 | const _Head& __head, const _Tail&... __tail) |
b8214660 JW |
253 | : _Inherited(__tag, __a, __tail...), |
254 | _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { } | |
255 | ||
256 | template<typename _Alloc, typename _UHead, typename... _UTail, | |
dd7b175e PC |
257 | typename = typename enable_if<sizeof...(_Tail) |
258 | == sizeof...(_UTail)>::type> | |
b8214660 JW |
259 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, |
260 | _UHead&& __head, _UTail&&... __tail) | |
261 | : _Inherited(__tag, __a, std::forward<_UTail>(__tail)...), | |
262 | _Base(__use_alloc<_Head, _Alloc, _UHead>(__a), | |
263 | std::forward<_UHead>(__head)) { } | |
264 | ||
265 | template<typename _Alloc> | |
266 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
267 | const _Tuple_impl& __in) | |
33ac58d5 | 268 | : _Inherited(__tag, __a, _M_tail(__in)), |
9480716c | 269 | _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { } |
b8214660 JW |
270 | |
271 | template<typename _Alloc> | |
272 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
273 | _Tuple_impl&& __in) | |
33ac58d5 | 274 | : _Inherited(__tag, __a, std::move(_M_tail(__in))), |
b8214660 | 275 | _Base(__use_alloc<_Head, _Alloc, _Head>(__a), |
9480716c | 276 | std::forward<_Head>(_M_head(__in))) { } |
b8214660 JW |
277 | |
278 | template<typename _Alloc, typename... _UElements> | |
279 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
280 | const _Tuple_impl<_Idx, _UElements...>& __in) | |
9480716c DK |
281 | : _Inherited(__tag, __a, |
282 | _Tuple_impl<_Idx, _UElements...>::_M_tail(__in)), | |
283 | _Base(__use_alloc<_Head, _Alloc, _Head>(__a), | |
284 | _Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { } | |
b8214660 JW |
285 | |
286 | template<typename _Alloc, typename _UHead, typename... _UTails> | |
287 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
288 | _Tuple_impl<_Idx, _UHead, _UTails...>&& __in) | |
9480716c DK |
289 | : _Inherited(__tag, __a, std::move |
290 | (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))), | |
b8214660 | 291 | _Base(__use_alloc<_Head, _Alloc, _UHead>(__a), |
9480716c DK |
292 | std::forward<_UHead> |
293 | (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { } | |
b8214660 | 294 | |
ba60f6f9 | 295 | template<typename... _UElements> |
a2c5e1ae JW |
296 | void |
297 | _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in) | |
ba60f6f9 | 298 | { |
9480716c | 299 | _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in); |
a2c5e1ae JW |
300 | _M_tail(*this)._M_assign( |
301 | _Tuple_impl<_Idx, _UElements...>::_M_tail(__in)); | |
ba60f6f9 PC |
302 | } |
303 | ||
78a869ec | 304 | template<typename _UHead, typename... _UTails> |
a2c5e1ae JW |
305 | void |
306 | _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in) | |
ba60f6f9 | 307 | { |
9480716c DK |
308 | _M_head(*this) = std::forward<_UHead> |
309 | (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)); | |
a2c5e1ae JW |
310 | _M_tail(*this)._M_assign( |
311 | std::move(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))); | |
ba60f6f9 | 312 | } |
3e93b275 | 313 | |
fe960d92 | 314 | protected: |
3e93b275 | 315 | void |
1aa1114b | 316 | _M_swap(_Tuple_impl& __in) |
3e93b275 | 317 | { |
1aa1114b | 318 | using std::swap; |
9480716c DK |
319 | swap(_M_head(*this), _M_head(__in)); |
320 | _Inherited::_M_swap(_M_tail(__in)); | |
3e93b275 | 321 | } |
894d0b15 CF |
322 | }; |
323 | ||
3ecec1ef JW |
324 | // Basis case of inheritance recursion. |
325 | template<std::size_t _Idx, typename _Head> | |
326 | struct _Tuple_impl<_Idx, _Head> | |
373c0095 | 327 | : private _Head_base<_Idx, _Head> |
3ecec1ef JW |
328 | { |
329 | template<std::size_t, typename...> friend class _Tuple_impl; | |
330 | ||
373c0095 | 331 | typedef _Head_base<_Idx, _Head> _Base; |
3ecec1ef JW |
332 | |
333 | static constexpr _Head& | |
334 | _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); } | |
335 | ||
336 | static constexpr const _Head& | |
337 | _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); } | |
338 | ||
339 | constexpr _Tuple_impl() | |
340 | : _Base() { } | |
341 | ||
342 | explicit | |
343 | constexpr _Tuple_impl(const _Head& __head) | |
344 | : _Base(__head) { } | |
345 | ||
3fe2ddae | 346 | template<typename _UHead> |
3ecec1ef JW |
347 | explicit |
348 | constexpr _Tuple_impl(_UHead&& __head) | |
349 | : _Base(std::forward<_UHead>(__head)) { } | |
350 | ||
351 | constexpr _Tuple_impl(const _Tuple_impl&) = default; | |
352 | ||
a2c5e1ae JW |
353 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
354 | // 2729. Missing SFINAE on std::pair::operator= | |
355 | _Tuple_impl& operator=(const _Tuple_impl&) = delete; | |
356 | ||
3ecec1ef | 357 | constexpr |
3fe2ddae | 358 | _Tuple_impl(_Tuple_impl&& __in) |
3ecec1ef JW |
359 | noexcept(is_nothrow_move_constructible<_Head>::value) |
360 | : _Base(std::forward<_Head>(_M_head(__in))) { } | |
361 | ||
3fe2ddae | 362 | template<typename _UHead> |
3ecec1ef JW |
363 | constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in) |
364 | : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in)) { } | |
365 | ||
3fe2ddae | 366 | template<typename _UHead> |
3ecec1ef JW |
367 | constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in) |
368 | : _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in))) | |
369 | { } | |
370 | ||
371 | template<typename _Alloc> | |
372 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a) | |
373 | : _Base(__tag, __use_alloc<_Head>(__a)) { } | |
374 | ||
375 | template<typename _Alloc> | |
376 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
377 | const _Head& __head) | |
378 | : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { } | |
379 | ||
380 | template<typename _Alloc, typename _UHead> | |
381 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
382 | _UHead&& __head) | |
383 | : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a), | |
384 | std::forward<_UHead>(__head)) { } | |
385 | ||
386 | template<typename _Alloc> | |
387 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
388 | const _Tuple_impl& __in) | |
389 | : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { } | |
390 | ||
391 | template<typename _Alloc> | |
392 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
393 | _Tuple_impl&& __in) | |
394 | : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), | |
395 | std::forward<_Head>(_M_head(__in))) { } | |
396 | ||
397 | template<typename _Alloc, typename _UHead> | |
398 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
399 | const _Tuple_impl<_Idx, _UHead>& __in) | |
400 | : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), | |
401 | _Tuple_impl<_Idx, _UHead>::_M_head(__in)) { } | |
402 | ||
403 | template<typename _Alloc, typename _UHead> | |
404 | _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, | |
405 | _Tuple_impl<_Idx, _UHead>&& __in) | |
406 | : _Base(__use_alloc<_Head, _Alloc, _UHead>(__a), | |
407 | std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in))) | |
408 | { } | |
409 | ||
3ecec1ef | 410 | template<typename _UHead> |
a2c5e1ae JW |
411 | void |
412 | _M_assign(const _Tuple_impl<_Idx, _UHead>& __in) | |
3ecec1ef JW |
413 | { |
414 | _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in); | |
3ecec1ef JW |
415 | } |
416 | ||
417 | template<typename _UHead> | |
a2c5e1ae JW |
418 | void |
419 | _M_assign(_Tuple_impl<_Idx, _UHead>&& __in) | |
3ecec1ef JW |
420 | { |
421 | _M_head(*this) | |
422 | = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)); | |
3ecec1ef JW |
423 | } |
424 | ||
425 | protected: | |
426 | void | |
427 | _M_swap(_Tuple_impl& __in) | |
3ecec1ef JW |
428 | { |
429 | using std::swap; | |
430 | swap(_M_head(*this), _M_head(__in)); | |
431 | } | |
432 | }; | |
433 | ||
bf7818bf VV |
434 | // Concept utility functions, reused in conditionally-explicit |
435 | // constructors. | |
436 | template<bool, typename... _Elements> | |
437 | struct _TC | |
438 | { | |
439 | template<typename... _UElements> | |
440 | static constexpr bool _ConstructibleTuple() | |
441 | { | |
442 | return __and_<is_constructible<_Elements, const _UElements&>...>::value; | |
443 | } | |
444 | ||
445 | template<typename... _UElements> | |
446 | static constexpr bool _ImplicitlyConvertibleTuple() | |
447 | { | |
448 | return __and_<is_convertible<const _UElements&, _Elements>...>::value; | |
449 | } | |
450 | ||
451 | template<typename... _UElements> | |
452 | static constexpr bool _MoveConstructibleTuple() | |
453 | { | |
454 | return __and_<is_constructible<_Elements, _UElements&&>...>::value; | |
455 | } | |
456 | ||
457 | template<typename... _UElements> | |
458 | static constexpr bool _ImplicitlyMoveConvertibleTuple() | |
459 | { | |
460 | return __and_<is_convertible<_UElements&&, _Elements>...>::value; | |
461 | } | |
5e2f2cd5 VV |
462 | |
463 | template<typename _SrcTuple> | |
464 | static constexpr bool _NonNestedTuple() | |
465 | { | |
057ce497 | 466 | return __and_<__not_<is_same<tuple<_Elements...>, |
a2c5e1ae | 467 | __remove_cvref_t<_SrcTuple>>>, |
057ce497 | 468 | __not_<is_convertible<_SrcTuple, _Elements...>>, |
5e2f2cd5 VV |
469 | __not_<is_constructible<_Elements..., _SrcTuple>> |
470 | >::value; | |
471 | } | |
a2c5e1ae | 472 | |
fb334765 VV |
473 | template<typename... _UElements> |
474 | static constexpr bool _NotSameTuple() | |
475 | { | |
476 | return __not_<is_same<tuple<_Elements...>, | |
a2c5e1ae | 477 | __remove_cvref_t<_UElements>...>>::value; |
fb334765 | 478 | } |
bf7818bf VV |
479 | }; |
480 | ||
481 | template<typename... _Elements> | |
482 | struct _TC<false, _Elements...> | |
483 | { | |
484 | template<typename... _UElements> | |
485 | static constexpr bool _ConstructibleTuple() | |
486 | { | |
487 | return false; | |
488 | } | |
489 | ||
490 | template<typename... _UElements> | |
491 | static constexpr bool _ImplicitlyConvertibleTuple() | |
492 | { | |
493 | return false; | |
494 | } | |
495 | ||
496 | template<typename... _UElements> | |
497 | static constexpr bool _MoveConstructibleTuple() | |
498 | { | |
499 | return false; | |
500 | } | |
501 | ||
502 | template<typename... _UElements> | |
503 | static constexpr bool _ImplicitlyMoveConvertibleTuple() | |
504 | { | |
505 | return false; | |
506 | } | |
5e2f2cd5 VV |
507 | |
508 | template<typename... _UElements> | |
509 | static constexpr bool _NonNestedTuple() | |
510 | { | |
511 | return true; | |
512 | } | |
a2c5e1ae | 513 | |
fb334765 VV |
514 | template<typename... _UElements> |
515 | static constexpr bool _NotSameTuple() | |
516 | { | |
a2c5e1ae | 517 | return true; |
fb334765 | 518 | } |
bf7818bf VV |
519 | }; |
520 | ||
2c4caf0a | 521 | /// Primary class template, tuple |
33ac58d5 | 522 | template<typename... _Elements> |
a2c5e1ae | 523 | class tuple : public _Tuple_impl<0, _Elements...> |
894d0b15 CF |
524 | { |
525 | typedef _Tuple_impl<0, _Elements...> _Inherited; | |
526 | ||
bf7818bf VV |
527 | // Used for constraining the default constructor so |
528 | // that it becomes dependent on the constraints. | |
529 | template<typename _Dummy> | |
530 | struct _TC2 | |
531 | { | |
532 | static constexpr bool _DefaultConstructibleTuple() | |
533 | { | |
534 | return __and_<is_default_constructible<_Elements>...>::value; | |
535 | } | |
f7632193 VV |
536 | static constexpr bool _ImplicitlyDefaultConstructibleTuple() |
537 | { | |
538 | return __and_<__is_implicitly_default_constructible<_Elements>...> | |
539 | ::value; | |
540 | } | |
bf7818bf VV |
541 | }; |
542 | ||
478490f6 JW |
543 | template<typename... _UElements> |
544 | static constexpr | |
545 | __enable_if_t<sizeof...(_UElements) == sizeof...(_Elements), bool> | |
546 | __assignable() | |
547 | { return __and_<is_assignable<_Elements&, _UElements>...>::value; } | |
548 | ||
549 | template<typename... _UElements> | |
550 | static constexpr bool __nothrow_assignable() | |
551 | { | |
552 | return | |
553 | __and_<is_nothrow_assignable<_Elements&, _UElements>...>::value; | |
554 | } | |
ec087ba3 NDR |
555 | template<typename... _UElements> |
556 | static constexpr bool __nothrow_constructible() | |
557 | { | |
558 | return | |
559 | __and_<is_nothrow_constructible<_Elements, _UElements>...>::value; | |
560 | } | |
478490f6 | 561 | |
894d0b15 | 562 | public: |
bf7818bf VV |
563 | template<typename _Dummy = void, |
564 | typename enable_if<_TC2<_Dummy>:: | |
f7632193 | 565 | _ImplicitlyDefaultConstructibleTuple(), |
bf7818bf | 566 | bool>::type = true> |
0e6ac87e | 567 | constexpr tuple() |
ec087ba3 | 568 | noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value) |
894d0b15 CF |
569 | : _Inherited() { } |
570 | ||
f7632193 VV |
571 | template<typename _Dummy = void, |
572 | typename enable_if<_TC2<_Dummy>:: | |
573 | _DefaultConstructibleTuple() | |
574 | && | |
575 | !_TC2<_Dummy>:: | |
576 | _ImplicitlyDefaultConstructibleTuple(), | |
577 | bool>::type = false> | |
578 | explicit constexpr tuple() | |
ec087ba3 | 579 | noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value) |
f7632193 VV |
580 | : _Inherited() { } |
581 | ||
bf7818bf VV |
582 | // Shortcut for the cases where constructors taking _Elements... |
583 | // need to be constrained. | |
584 | template<typename _Dummy> using _TCC = | |
585 | _TC<is_same<_Dummy, void>::value, | |
586 | _Elements...>; | |
587 | ||
588 | template<typename _Dummy = void, | |
589 | typename enable_if< | |
590 | _TCC<_Dummy>::template | |
591 | _ConstructibleTuple<_Elements...>() | |
592 | && _TCC<_Dummy>::template | |
593 | _ImplicitlyConvertibleTuple<_Elements...>() | |
594 | && (sizeof...(_Elements) >= 1), | |
595 | bool>::type=true> | |
596 | constexpr tuple(const _Elements&... __elements) | |
ec087ba3 | 597 | noexcept(__nothrow_constructible<const _Elements&...>()) |
894d0b15 CF |
598 | : _Inherited(__elements...) { } |
599 | ||
bf7818bf VV |
600 | template<typename _Dummy = void, |
601 | typename enable_if< | |
602 | _TCC<_Dummy>::template | |
603 | _ConstructibleTuple<_Elements...>() | |
604 | && !_TCC<_Dummy>::template | |
605 | _ImplicitlyConvertibleTuple<_Elements...>() | |
606 | && (sizeof...(_Elements) >= 1), | |
607 | bool>::type=false> | |
608 | explicit constexpr tuple(const _Elements&... __elements) | |
ec087ba3 | 609 | noexcept(__nothrow_constructible<const _Elements&...>()) |
bf7818bf VV |
610 | : _Inherited(__elements...) { } |
611 | ||
612 | // Shortcut for the cases where constructors taking _UElements... | |
613 | // need to be constrained. | |
614 | template<typename... _UElements> using _TMC = | |
b7021006 VV |
615 | _TC<(sizeof...(_Elements) == sizeof...(_UElements)) |
616 | && (_TC<(sizeof...(_UElements)==1), _Elements...>:: | |
617 | template _NotSameTuple<_UElements...>()), | |
618 | _Elements...>; | |
619 | ||
620 | // Shortcut for the cases where constructors taking tuple<_UElements...> | |
621 | // need to be constrained. | |
622 | template<typename... _UElements> using _TMCT = | |
623 | _TC<(sizeof...(_Elements) == sizeof...(_UElements)) | |
48035dfb | 624 | && !is_same<tuple<_Elements...>, |
b7021006 | 625 | tuple<_UElements...>>::value, |
bf7818bf VV |
626 | _Elements...>; |
627 | ||
628 | template<typename... _UElements, typename | |
fb334765 | 629 | enable_if< |
b7021006 | 630 | _TMC<_UElements...>::template |
bf7818bf VV |
631 | _MoveConstructibleTuple<_UElements...>() |
632 | && _TMC<_UElements...>::template | |
633 | _ImplicitlyMoveConvertibleTuple<_UElements...>() | |
634 | && (sizeof...(_Elements) >= 1), | |
635 | bool>::type=true> | |
2c4caf0a | 636 | constexpr tuple(_UElements&&... __elements) |
ec087ba3 | 637 | noexcept(__nothrow_constructible<_UElements...>()) |
bf7818bf VV |
638 | : _Inherited(std::forward<_UElements>(__elements)...) { } |
639 | ||
640 | template<typename... _UElements, typename | |
fb334765 | 641 | enable_if< |
b7021006 | 642 | _TMC<_UElements...>::template |
bf7818bf VV |
643 | _MoveConstructibleTuple<_UElements...>() |
644 | && !_TMC<_UElements...>::template | |
645 | _ImplicitlyMoveConvertibleTuple<_UElements...>() | |
646 | && (sizeof...(_Elements) >= 1), | |
647 | bool>::type=false> | |
648 | explicit constexpr tuple(_UElements&&... __elements) | |
ec087ba3 | 649 | noexcept(__nothrow_constructible<_UElements...>()) |
b5b5e640 | 650 | : _Inherited(std::forward<_UElements>(__elements)...) { } |
894d0b15 | 651 | |
094a14ef | 652 | constexpr tuple(const tuple&) = default; |
2c4caf0a | 653 | |
33ac58d5 | 654 | constexpr tuple(tuple&&) = default; |
ba60f6f9 | 655 | |
5e2f2cd5 VV |
656 | // Shortcut for the cases where constructors taking tuples |
657 | // must avoid creating temporaries. | |
658 | template<typename _Dummy> using _TNTC = | |
659 | _TC<is_same<_Dummy, void>::value && sizeof...(_Elements) == 1, | |
660 | _Elements...>; | |
661 | ||
662 | template<typename... _UElements, typename _Dummy = void, typename | |
b7021006 | 663 | enable_if<_TMCT<_UElements...>::template |
bf7818bf | 664 | _ConstructibleTuple<_UElements...>() |
b7021006 | 665 | && _TMCT<_UElements...>::template |
5e2f2cd5 VV |
666 | _ImplicitlyConvertibleTuple<_UElements...>() |
667 | && _TNTC<_Dummy>::template | |
668 | _NonNestedTuple<const tuple<_UElements...>&>(), | |
bf7818bf | 669 | bool>::type=true> |
a7d0c94e | 670 | constexpr tuple(const tuple<_UElements...>& __in) |
ec087ba3 | 671 | noexcept(__nothrow_constructible<const _UElements&...>()) |
0a5c2065 PC |
672 | : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in)) |
673 | { } | |
ba60f6f9 | 674 | |
5e2f2cd5 | 675 | template<typename... _UElements, typename _Dummy = void, typename |
b7021006 | 676 | enable_if<_TMCT<_UElements...>::template |
bf7818bf | 677 | _ConstructibleTuple<_UElements...>() |
b7021006 | 678 | && !_TMCT<_UElements...>::template |
5e2f2cd5 VV |
679 | _ImplicitlyConvertibleTuple<_UElements...>() |
680 | && _TNTC<_Dummy>::template | |
681 | _NonNestedTuple<const tuple<_UElements...>&>(), | |
bf7818bf VV |
682 | bool>::type=false> |
683 | explicit constexpr tuple(const tuple<_UElements...>& __in) | |
ec087ba3 | 684 | noexcept(__nothrow_constructible<const _UElements&...>()) |
bf7818bf VV |
685 | : _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in)) |
686 | { } | |
687 | ||
5e2f2cd5 | 688 | template<typename... _UElements, typename _Dummy = void, typename |
b7021006 | 689 | enable_if<_TMCT<_UElements...>::template |
bf7818bf | 690 | _MoveConstructibleTuple<_UElements...>() |
b7021006 | 691 | && _TMCT<_UElements...>::template |
5e2f2cd5 VV |
692 | _ImplicitlyMoveConvertibleTuple<_UElements...>() |
693 | && _TNTC<_Dummy>::template | |
694 | _NonNestedTuple<tuple<_UElements...>&&>(), | |
bf7818bf | 695 | bool>::type=true> |
a7d0c94e | 696 | constexpr tuple(tuple<_UElements...>&& __in) |
ec087ba3 | 697 | noexcept(__nothrow_constructible<_UElements...>()) |
0a5c2065 | 698 | : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { } |
894d0b15 | 699 | |
5e2f2cd5 | 700 | template<typename... _UElements, typename _Dummy = void, typename |
b7021006 | 701 | enable_if<_TMCT<_UElements...>::template |
bf7818bf | 702 | _MoveConstructibleTuple<_UElements...>() |
b7021006 | 703 | && !_TMCT<_UElements...>::template |
5e2f2cd5 VV |
704 | _ImplicitlyMoveConvertibleTuple<_UElements...>() |
705 | && _TNTC<_Dummy>::template | |
706 | _NonNestedTuple<tuple<_UElements...>&&>(), | |
bf7818bf VV |
707 | bool>::type=false> |
708 | explicit constexpr tuple(tuple<_UElements...>&& __in) | |
ec087ba3 | 709 | noexcept(__nothrow_constructible<_UElements...>()) |
bf7818bf VV |
710 | : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { } |
711 | ||
2c4caf0a | 712 | // Allocator-extended constructors. |
b8214660 JW |
713 | |
714 | template<typename _Alloc> | |
715 | tuple(allocator_arg_t __tag, const _Alloc& __a) | |
716 | : _Inherited(__tag, __a) { } | |
717 | ||
bf7818bf VV |
718 | template<typename _Alloc, typename _Dummy = void, |
719 | typename enable_if< | |
720 | _TCC<_Dummy>::template | |
721 | _ConstructibleTuple<_Elements...>() | |
722 | && _TCC<_Dummy>::template | |
723 | _ImplicitlyConvertibleTuple<_Elements...>(), | |
724 | bool>::type=true> | |
b8214660 JW |
725 | tuple(allocator_arg_t __tag, const _Alloc& __a, |
726 | const _Elements&... __elements) | |
727 | : _Inherited(__tag, __a, __elements...) { } | |
728 | ||
bf7818bf VV |
729 | template<typename _Alloc, typename _Dummy = void, |
730 | typename enable_if< | |
731 | _TCC<_Dummy>::template | |
732 | _ConstructibleTuple<_Elements...>() | |
733 | && !_TCC<_Dummy>::template | |
734 | _ImplicitlyConvertibleTuple<_Elements...>(), | |
735 | bool>::type=false> | |
736 | explicit tuple(allocator_arg_t __tag, const _Alloc& __a, | |
737 | const _Elements&... __elements) | |
738 | : _Inherited(__tag, __a, __elements...) { } | |
739 | ||
740 | template<typename _Alloc, typename... _UElements, typename | |
741 | enable_if<_TMC<_UElements...>::template | |
742 | _MoveConstructibleTuple<_UElements...>() | |
743 | && _TMC<_UElements...>::template | |
744 | _ImplicitlyMoveConvertibleTuple<_UElements...>(), | |
745 | bool>::type=true> | |
b8214660 JW |
746 | tuple(allocator_arg_t __tag, const _Alloc& __a, |
747 | _UElements&&... __elements) | |
748 | : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...) | |
749 | { } | |
750 | ||
bf7818bf VV |
751 | template<typename _Alloc, typename... _UElements, typename |
752 | enable_if<_TMC<_UElements...>::template | |
753 | _MoveConstructibleTuple<_UElements...>() | |
754 | && !_TMC<_UElements...>::template | |
755 | _ImplicitlyMoveConvertibleTuple<_UElements...>(), | |
756 | bool>::type=false> | |
757 | explicit tuple(allocator_arg_t __tag, const _Alloc& __a, | |
758 | _UElements&&... __elements) | |
759 | : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...) | |
760 | { } | |
761 | ||
b8214660 JW |
762 | template<typename _Alloc> |
763 | tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in) | |
764 | : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { } | |
765 | ||
766 | template<typename _Alloc> | |
767 | tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in) | |
768 | : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { } | |
769 | ||
7a667453 VV |
770 | template<typename _Alloc, typename _Dummy = void, |
771 | typename... _UElements, typename | |
b7021006 | 772 | enable_if<_TMCT<_UElements...>::template |
bf7818bf | 773 | _ConstructibleTuple<_UElements...>() |
b7021006 | 774 | && _TMCT<_UElements...>::template |
7a667453 VV |
775 | _ImplicitlyConvertibleTuple<_UElements...>() |
776 | && _TNTC<_Dummy>::template | |
777 | _NonNestedTuple<tuple<_UElements...>&&>(), | |
bf7818bf | 778 | bool>::type=true> |
b8214660 JW |
779 | tuple(allocator_arg_t __tag, const _Alloc& __a, |
780 | const tuple<_UElements...>& __in) | |
781 | : _Inherited(__tag, __a, | |
782 | static_cast<const _Tuple_impl<0, _UElements...>&>(__in)) | |
783 | { } | |
784 | ||
7a667453 VV |
785 | template<typename _Alloc, typename _Dummy = void, |
786 | typename... _UElements, typename | |
b7021006 | 787 | enable_if<_TMCT<_UElements...>::template |
bf7818bf | 788 | _ConstructibleTuple<_UElements...>() |
b7021006 | 789 | && !_TMCT<_UElements...>::template |
7a667453 VV |
790 | _ImplicitlyConvertibleTuple<_UElements...>() |
791 | && _TNTC<_Dummy>::template | |
792 | _NonNestedTuple<tuple<_UElements...>&&>(), | |
bf7818bf VV |
793 | bool>::type=false> |
794 | explicit tuple(allocator_arg_t __tag, const _Alloc& __a, | |
795 | const tuple<_UElements...>& __in) | |
796 | : _Inherited(__tag, __a, | |
797 | static_cast<const _Tuple_impl<0, _UElements...>&>(__in)) | |
798 | { } | |
799 | ||
7a667453 VV |
800 | template<typename _Alloc, typename _Dummy = void, |
801 | typename... _UElements, typename | |
b7021006 | 802 | enable_if<_TMCT<_UElements...>::template |
bf7818bf | 803 | _MoveConstructibleTuple<_UElements...>() |
b7021006 | 804 | && _TMCT<_UElements...>::template |
7a667453 VV |
805 | _ImplicitlyMoveConvertibleTuple<_UElements...>() |
806 | && _TNTC<_Dummy>::template | |
807 | _NonNestedTuple<tuple<_UElements...>&&>(), | |
bf7818bf | 808 | bool>::type=true> |
b8214660 JW |
809 | tuple(allocator_arg_t __tag, const _Alloc& __a, |
810 | tuple<_UElements...>&& __in) | |
811 | : _Inherited(__tag, __a, | |
812 | static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) | |
813 | { } | |
814 | ||
7a667453 VV |
815 | template<typename _Alloc, typename _Dummy = void, |
816 | typename... _UElements, typename | |
b7021006 | 817 | enable_if<_TMCT<_UElements...>::template |
bf7818bf | 818 | _MoveConstructibleTuple<_UElements...>() |
b7021006 | 819 | && !_TMCT<_UElements...>::template |
7a667453 VV |
820 | _ImplicitlyMoveConvertibleTuple<_UElements...>() |
821 | && _TNTC<_Dummy>::template | |
822 | _NonNestedTuple<tuple<_UElements...>&&>(), | |
bf7818bf VV |
823 | bool>::type=false> |
824 | explicit tuple(allocator_arg_t __tag, const _Alloc& __a, | |
825 | tuple<_UElements...>&& __in) | |
826 | : _Inherited(__tag, __a, | |
827 | static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) | |
828 | { } | |
829 | ||
a2c5e1ae JW |
830 | // tuple assignment |
831 | ||
894d0b15 | 832 | tuple& |
478490f6 JW |
833 | operator=(typename conditional<__assignable<const _Elements&...>(), |
834 | const tuple&, | |
835 | const __nonesuch_no_braces&>::type __in) | |
836 | noexcept(__nothrow_assignable<const _Elements&...>()) | |
894d0b15 | 837 | { |
a2c5e1ae | 838 | this->_M_assign(__in); |
894d0b15 CF |
839 | return *this; |
840 | } | |
ba60f6f9 PC |
841 | |
842 | tuple& | |
478490f6 JW |
843 | operator=(typename conditional<__assignable<_Elements...>(), |
844 | tuple&&, | |
845 | __nonesuch_no_braces&&>::type __in) | |
846 | noexcept(__nothrow_assignable<_Elements...>()) | |
ba60f6f9 | 847 | { |
a2c5e1ae | 848 | this->_M_assign(std::move(__in)); |
ba60f6f9 PC |
849 | return *this; |
850 | } | |
851 | ||
ca9e949f | 852 | template<typename... _UElements> |
478490f6 JW |
853 | __enable_if_t<__assignable<const _UElements&...>(), tuple&> |
854 | operator=(const tuple<_UElements...>& __in) | |
855 | noexcept(__nothrow_assignable<const _UElements&...>()) | |
856 | { | |
a2c5e1ae | 857 | this->_M_assign(__in); |
ba60f6f9 PC |
858 | return *this; |
859 | } | |
860 | ||
ca9e949f | 861 | template<typename... _UElements> |
478490f6 JW |
862 | __enable_if_t<__assignable<_UElements...>(), tuple&> |
863 | operator=(tuple<_UElements...>&& __in) | |
864 | noexcept(__nothrow_assignable<_UElements...>()) | |
865 | { | |
a2c5e1ae | 866 | this->_M_assign(std::move(__in)); |
ba60f6f9 PC |
867 | return *this; |
868 | } | |
3e93b275 | 869 | |
a2c5e1ae | 870 | // tuple swap |
3e93b275 | 871 | void |
ff74fd13 | 872 | swap(tuple& __in) |
a2c5e1ae | 873 | noexcept(__and_<__is_nothrow_swappable<_Elements>...>::value) |
1aa1114b | 874 | { _Inherited::_M_swap(__in); } |
894d0b15 CF |
875 | }; |
876 | ||
af181c91 JW |
877 | #if __cpp_deduction_guides >= 201606 |
878 | template<typename... _UTypes> | |
879 | tuple(_UTypes...) -> tuple<_UTypes...>; | |
880 | template<typename _T1, typename _T2> | |
881 | tuple(pair<_T1, _T2>) -> tuple<_T1, _T2>; | |
882 | template<typename _Alloc, typename... _UTypes> | |
883 | tuple(allocator_arg_t, _Alloc, _UTypes...) -> tuple<_UTypes...>; | |
884 | template<typename _Alloc, typename _T1, typename _T2> | |
885 | tuple(allocator_arg_t, _Alloc, pair<_T1, _T2>) -> tuple<_T1, _T2>; | |
886 | template<typename _Alloc, typename... _UTypes> | |
887 | tuple(allocator_arg_t, _Alloc, tuple<_UTypes...>) -> tuple<_UTypes...>; | |
888 | #endif | |
889 | ||
2c4caf0a | 890 | // Explicit specialization, zero-element tuple. |
bf7818bf | 891 | template<> |
3e93b275 CF |
892 | class tuple<> |
893 | { | |
894 | public: | |
1aa1114b | 895 | void swap(tuple&) noexcept { /* no-op */ } |
dbc6221f VV |
896 | // We need the default since we're going to define no-op |
897 | // allocator constructors. | |
898 | tuple() = default; | |
899 | // No-op allocator constructors. | |
900 | template<typename _Alloc> | |
901 | tuple(allocator_arg_t, const _Alloc&) { } | |
902 | template<typename _Alloc> | |
903 | tuple(allocator_arg_t, const _Alloc&, const tuple&) { } | |
3e93b275 | 904 | }; |
939759fc | 905 | |
2c4caf0a BK |
906 | /// Partial specialization, 2-element tuple. |
907 | /// Includes construction and assignment from a pair. | |
894d0b15 | 908 | template<typename _T1, typename _T2> |
a2c5e1ae | 909 | class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2> |
894d0b15 CF |
910 | { |
911 | typedef _Tuple_impl<0, _T1, _T2> _Inherited; | |
912 | ||
478490f6 JW |
913 | template<typename _U1, typename _U2> |
914 | static constexpr bool __assignable() | |
915 | { | |
916 | return __and_<is_assignable<_T1&, _U1>, | |
917 | is_assignable<_T2&, _U2>>::value; | |
918 | } | |
919 | ||
920 | template<typename _U1, typename _U2> | |
921 | static constexpr bool __nothrow_assignable() | |
922 | { | |
923 | return __and_<is_nothrow_assignable<_T1&, _U1>, | |
924 | is_nothrow_assignable<_T2&, _U2>>::value; | |
925 | } | |
926 | ||
ec087ba3 NDR |
927 | template<typename _U1, typename _U2> |
928 | static constexpr bool __nothrow_constructible() | |
929 | { | |
930 | return __and_<is_nothrow_constructible<_T1, _U1>, | |
931 | is_nothrow_constructible<_T2, _U2>>::value; | |
932 | } | |
933 | ||
894d0b15 | 934 | public: |
bf7818bf VV |
935 | template <typename _U1 = _T1, |
936 | typename _U2 = _T2, | |
937 | typename enable_if<__and_< | |
f7632193 VV |
938 | __is_implicitly_default_constructible<_U1>, |
939 | __is_implicitly_default_constructible<_U2>> | |
bf7818bf | 940 | ::value, bool>::type = true> |
478490f6 | 941 | constexpr tuple() |
ec087ba3 NDR |
942 | noexcept(__and_<is_nothrow_default_constructible<_T1>, |
943 | is_nothrow_default_constructible<_T2>>::value) | |
478490f6 | 944 | : _Inherited() { } |
894d0b15 | 945 | |
f7632193 VV |
946 | template <typename _U1 = _T1, |
947 | typename _U2 = _T2, | |
948 | typename enable_if< | |
949 | __and_< | |
950 | is_default_constructible<_U1>, | |
951 | is_default_constructible<_U2>, | |
952 | __not_< | |
953 | __and_<__is_implicitly_default_constructible<_U1>, | |
954 | __is_implicitly_default_constructible<_U2>>>> | |
955 | ::value, bool>::type = false> | |
478490f6 | 956 | explicit constexpr tuple() |
ec087ba3 NDR |
957 | noexcept(__and_<is_nothrow_default_constructible<_T1>, |
958 | is_nothrow_default_constructible<_T2>>::value) | |
478490f6 | 959 | : _Inherited() { } |
f7632193 | 960 | |
bf7818bf VV |
961 | // Shortcut for the cases where constructors taking _T1, _T2 |
962 | // need to be constrained. | |
963 | template<typename _Dummy> using _TCC = | |
964 | _TC<is_same<_Dummy, void>::value, _T1, _T2>; | |
965 | ||
966 | template<typename _Dummy = void, typename | |
967 | enable_if<_TCC<_Dummy>::template | |
968 | _ConstructibleTuple<_T1, _T2>() | |
969 | && _TCC<_Dummy>::template | |
970 | _ImplicitlyConvertibleTuple<_T1, _T2>(), | |
971 | bool>::type = true> | |
972 | constexpr tuple(const _T1& __a1, const _T2& __a2) | |
ec087ba3 | 973 | noexcept(__nothrow_constructible<const _T1&, const _T2&>()) |
bf7818bf VV |
974 | : _Inherited(__a1, __a2) { } |
975 | ||
976 | template<typename _Dummy = void, typename | |
977 | enable_if<_TCC<_Dummy>::template | |
978 | _ConstructibleTuple<_T1, _T2>() | |
979 | && !_TCC<_Dummy>::template | |
980 | _ImplicitlyConvertibleTuple<_T1, _T2>(), | |
981 | bool>::type = false> | |
982 | explicit constexpr tuple(const _T1& __a1, const _T2& __a2) | |
ec087ba3 | 983 | noexcept(__nothrow_constructible<const _T1&, const _T2&>()) |
bf7818bf VV |
984 | : _Inherited(__a1, __a2) { } |
985 | ||
986 | // Shortcut for the cases where constructors taking _U1, _U2 | |
987 | // need to be constrained. | |
988 | using _TMC = _TC<true, _T1, _T2>; | |
989 | ||
990 | template<typename _U1, typename _U2, typename | |
991 | enable_if<_TMC::template | |
992 | _MoveConstructibleTuple<_U1, _U2>() | |
993 | && _TMC::template | |
4b21c3ea | 994 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>() |
a2c5e1ae | 995 | && !is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value, |
bf7818bf | 996 | bool>::type = true> |
2c4caf0a | 997 | constexpr tuple(_U1&& __a1, _U2&& __a2) |
ec087ba3 | 998 | noexcept(__nothrow_constructible<_U1, _U2>()) |
ba60f6f9 | 999 | : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { } |
894d0b15 | 1000 | |
bf7818bf VV |
1001 | template<typename _U1, typename _U2, typename |
1002 | enable_if<_TMC::template | |
1003 | _MoveConstructibleTuple<_U1, _U2>() | |
1004 | && !_TMC::template | |
4b21c3ea | 1005 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>() |
a2c5e1ae | 1006 | && !is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value, |
bf7818bf VV |
1007 | bool>::type = false> |
1008 | explicit constexpr tuple(_U1&& __a1, _U2&& __a2) | |
ec087ba3 | 1009 | noexcept(__nothrow_constructible<_U1, _U2>()) |
bf7818bf VV |
1010 | : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { } |
1011 | ||
094a14ef | 1012 | constexpr tuple(const tuple&) = default; |
2c4caf0a | 1013 | |
a7d0c94e | 1014 | constexpr tuple(tuple&&) = default; |
ba60f6f9 | 1015 | |
bf7818bf VV |
1016 | template<typename _U1, typename _U2, typename |
1017 | enable_if<_TMC::template | |
1018 | _ConstructibleTuple<_U1, _U2>() | |
1019 | && _TMC::template | |
1020 | _ImplicitlyConvertibleTuple<_U1, _U2>(), | |
1021 | bool>::type = true> | |
a7d0c94e | 1022 | constexpr tuple(const tuple<_U1, _U2>& __in) |
ec087ba3 | 1023 | noexcept(__nothrow_constructible<const _U1&, const _U2&>()) |
b5b5e640 | 1024 | : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { } |
ba60f6f9 | 1025 | |
bf7818bf VV |
1026 | template<typename _U1, typename _U2, typename |
1027 | enable_if<_TMC::template | |
1028 | _ConstructibleTuple<_U1, _U2>() | |
1029 | && !_TMC::template | |
1030 | _ImplicitlyConvertibleTuple<_U1, _U2>(), | |
1031 | bool>::type = false> | |
1032 | explicit constexpr tuple(const tuple<_U1, _U2>& __in) | |
ec087ba3 | 1033 | noexcept(__nothrow_constructible<const _U1&, const _U2&>()) |
bf7818bf VV |
1034 | : _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { } |
1035 | ||
1036 | template<typename _U1, typename _U2, typename | |
1037 | enable_if<_TMC::template | |
1038 | _MoveConstructibleTuple<_U1, _U2>() | |
1039 | && _TMC::template | |
1040 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>(), | |
1041 | bool>::type = true> | |
a7d0c94e | 1042 | constexpr tuple(tuple<_U1, _U2>&& __in) |
ec087ba3 | 1043 | noexcept(__nothrow_constructible<_U1, _U2>()) |
4c650853 | 1044 | : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { } |
ba60f6f9 | 1045 | |
bf7818bf VV |
1046 | template<typename _U1, typename _U2, typename |
1047 | enable_if<_TMC::template | |
1048 | _MoveConstructibleTuple<_U1, _U2>() | |
1049 | && !_TMC::template | |
1050 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>(), | |
1051 | bool>::type = false> | |
1052 | explicit constexpr tuple(tuple<_U1, _U2>&& __in) | |
ec087ba3 | 1053 | noexcept(__nothrow_constructible<_U1, _U2>()) |
bf7818bf VV |
1054 | : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { } |
1055 | ||
1056 | template<typename _U1, typename _U2, typename | |
1057 | enable_if<_TMC::template | |
1058 | _ConstructibleTuple<_U1, _U2>() | |
1059 | && _TMC::template | |
1060 | _ImplicitlyConvertibleTuple<_U1, _U2>(), | |
1061 | bool>::type = true> | |
2c4caf0a | 1062 | constexpr tuple(const pair<_U1, _U2>& __in) |
ec087ba3 | 1063 | noexcept(__nothrow_constructible<const _U1&, const _U2&>()) |
b5b5e640 | 1064 | : _Inherited(__in.first, __in.second) { } |
ba60f6f9 | 1065 | |
bf7818bf VV |
1066 | template<typename _U1, typename _U2, typename |
1067 | enable_if<_TMC::template | |
1068 | _ConstructibleTuple<_U1, _U2>() | |
1069 | && !_TMC::template | |
1070 | _ImplicitlyConvertibleTuple<_U1, _U2>(), | |
1071 | bool>::type = false> | |
1072 | explicit constexpr tuple(const pair<_U1, _U2>& __in) | |
ec087ba3 | 1073 | noexcept(__nothrow_constructible<const _U1&, const _U2&>()) |
bf7818bf VV |
1074 | : _Inherited(__in.first, __in.second) { } |
1075 | ||
1076 | template<typename _U1, typename _U2, typename | |
1077 | enable_if<_TMC::template | |
1078 | _MoveConstructibleTuple<_U1, _U2>() | |
1079 | && _TMC::template | |
1080 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>(), | |
1081 | bool>::type = true> | |
fae3f459 | 1082 | constexpr tuple(pair<_U1, _U2>&& __in) |
ec087ba3 | 1083 | noexcept(__nothrow_constructible<_U1, _U2>()) |
87b2e746 PC |
1084 | : _Inherited(std::forward<_U1>(__in.first), |
1085 | std::forward<_U2>(__in.second)) { } | |
894d0b15 | 1086 | |
bf7818bf VV |
1087 | template<typename _U1, typename _U2, typename |
1088 | enable_if<_TMC::template | |
1089 | _MoveConstructibleTuple<_U1, _U2>() | |
1090 | && !_TMC::template | |
1091 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>(), | |
1092 | bool>::type = false> | |
1093 | explicit constexpr tuple(pair<_U1, _U2>&& __in) | |
ec087ba3 | 1094 | noexcept(__nothrow_constructible<_U1, _U2>()) |
bf7818bf VV |
1095 | : _Inherited(std::forward<_U1>(__in.first), |
1096 | std::forward<_U2>(__in.second)) { } | |
1097 | ||
2c4caf0a | 1098 | // Allocator-extended constructors. |
b8214660 JW |
1099 | |
1100 | template<typename _Alloc> | |
1101 | tuple(allocator_arg_t __tag, const _Alloc& __a) | |
1102 | : _Inherited(__tag, __a) { } | |
1103 | ||
bf7818bf VV |
1104 | template<typename _Alloc, typename _Dummy = void, |
1105 | typename enable_if< | |
1106 | _TCC<_Dummy>::template | |
1107 | _ConstructibleTuple<_T1, _T2>() | |
1108 | && _TCC<_Dummy>::template | |
1109 | _ImplicitlyConvertibleTuple<_T1, _T2>(), | |
1110 | bool>::type=true> | |
1111 | ||
b8214660 JW |
1112 | tuple(allocator_arg_t __tag, const _Alloc& __a, |
1113 | const _T1& __a1, const _T2& __a2) | |
1114 | : _Inherited(__tag, __a, __a1, __a2) { } | |
1115 | ||
bf7818bf VV |
1116 | template<typename _Alloc, typename _Dummy = void, |
1117 | typename enable_if< | |
1118 | _TCC<_Dummy>::template | |
1119 | _ConstructibleTuple<_T1, _T2>() | |
1120 | && !_TCC<_Dummy>::template | |
1121 | _ImplicitlyConvertibleTuple<_T1, _T2>(), | |
1122 | bool>::type=false> | |
1123 | ||
1124 | explicit tuple(allocator_arg_t __tag, const _Alloc& __a, | |
1125 | const _T1& __a1, const _T2& __a2) | |
1126 | : _Inherited(__tag, __a, __a1, __a2) { } | |
1127 | ||
1128 | template<typename _Alloc, typename _U1, typename _U2, typename | |
1129 | enable_if<_TMC::template | |
1130 | _MoveConstructibleTuple<_U1, _U2>() | |
1131 | && _TMC::template | |
1132 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>(), | |
1133 | bool>::type = true> | |
b8214660 JW |
1134 | tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2) |
1135 | : _Inherited(__tag, __a, std::forward<_U1>(__a1), | |
1136 | std::forward<_U2>(__a2)) { } | |
1137 | ||
bf7818bf VV |
1138 | template<typename _Alloc, typename _U1, typename _U2, typename |
1139 | enable_if<_TMC::template | |
1140 | _MoveConstructibleTuple<_U1, _U2>() | |
1141 | && !_TMC::template | |
1142 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>(), | |
1143 | bool>::type = false> | |
1144 | explicit tuple(allocator_arg_t __tag, const _Alloc& __a, | |
1145 | _U1&& __a1, _U2&& __a2) | |
1146 | : _Inherited(__tag, __a, std::forward<_U1>(__a1), | |
1147 | std::forward<_U2>(__a2)) { } | |
1148 | ||
b8214660 JW |
1149 | template<typename _Alloc> |
1150 | tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in) | |
1151 | : _Inherited(__tag, __a, static_cast<const _Inherited&>(__in)) { } | |
1152 | ||
1153 | template<typename _Alloc> | |
1154 | tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in) | |
1155 | : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { } | |
1156 | ||
bf7818bf VV |
1157 | template<typename _Alloc, typename _U1, typename _U2, typename |
1158 | enable_if<_TMC::template | |
1159 | _ConstructibleTuple<_U1, _U2>() | |
1160 | && _TMC::template | |
1161 | _ImplicitlyConvertibleTuple<_U1, _U2>(), | |
1162 | bool>::type = true> | |
b8214660 JW |
1163 | tuple(allocator_arg_t __tag, const _Alloc& __a, |
1164 | const tuple<_U1, _U2>& __in) | |
1165 | : _Inherited(__tag, __a, | |
1166 | static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) | |
1167 | { } | |
1168 | ||
bf7818bf VV |
1169 | template<typename _Alloc, typename _U1, typename _U2, typename |
1170 | enable_if<_TMC::template | |
1171 | _ConstructibleTuple<_U1, _U2>() | |
1172 | && !_TMC::template | |
1173 | _ImplicitlyConvertibleTuple<_U1, _U2>(), | |
1174 | bool>::type = false> | |
1175 | explicit tuple(allocator_arg_t __tag, const _Alloc& __a, | |
1176 | const tuple<_U1, _U2>& __in) | |
1177 | : _Inherited(__tag, __a, | |
1178 | static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) | |
1179 | { } | |
1180 | ||
1181 | template<typename _Alloc, typename _U1, typename _U2, typename | |
1182 | enable_if<_TMC::template | |
1183 | _MoveConstructibleTuple<_U1, _U2>() | |
1184 | && _TMC::template | |
1185 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>(), | |
1186 | bool>::type = true> | |
b8214660 JW |
1187 | tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in) |
1188 | : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) | |
1189 | { } | |
1190 | ||
bf7818bf VV |
1191 | template<typename _Alloc, typename _U1, typename _U2, typename |
1192 | enable_if<_TMC::template | |
1193 | _MoveConstructibleTuple<_U1, _U2>() | |
1194 | && !_TMC::template | |
1195 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>(), | |
1196 | bool>::type = false> | |
1197 | explicit tuple(allocator_arg_t __tag, const _Alloc& __a, | |
1198 | tuple<_U1, _U2>&& __in) | |
1199 | : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) | |
1200 | { } | |
1201 | ||
1202 | template<typename _Alloc, typename _U1, typename _U2, typename | |
1203 | enable_if<_TMC::template | |
1204 | _ConstructibleTuple<_U1, _U2>() | |
1205 | && _TMC::template | |
1206 | _ImplicitlyConvertibleTuple<_U1, _U2>(), | |
1207 | bool>::type = true> | |
b8214660 JW |
1208 | tuple(allocator_arg_t __tag, const _Alloc& __a, |
1209 | const pair<_U1, _U2>& __in) | |
1210 | : _Inherited(__tag, __a, __in.first, __in.second) { } | |
1211 | ||
bf7818bf VV |
1212 | template<typename _Alloc, typename _U1, typename _U2, typename |
1213 | enable_if<_TMC::template | |
1214 | _ConstructibleTuple<_U1, _U2>() | |
1215 | && !_TMC::template | |
1216 | _ImplicitlyConvertibleTuple<_U1, _U2>(), | |
1217 | bool>::type = false> | |
1218 | explicit tuple(allocator_arg_t __tag, const _Alloc& __a, | |
1219 | const pair<_U1, _U2>& __in) | |
1220 | : _Inherited(__tag, __a, __in.first, __in.second) { } | |
1221 | ||
1222 | template<typename _Alloc, typename _U1, typename _U2, typename | |
1223 | enable_if<_TMC::template | |
1224 | _MoveConstructibleTuple<_U1, _U2>() | |
1225 | && _TMC::template | |
1226 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>(), | |
1227 | bool>::type = true> | |
b8214660 JW |
1228 | tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in) |
1229 | : _Inherited(__tag, __a, std::forward<_U1>(__in.first), | |
1230 | std::forward<_U2>(__in.second)) { } | |
1231 | ||
bf7818bf VV |
1232 | template<typename _Alloc, typename _U1, typename _U2, typename |
1233 | enable_if<_TMC::template | |
1234 | _MoveConstructibleTuple<_U1, _U2>() | |
1235 | && !_TMC::template | |
1236 | _ImplicitlyMoveConvertibleTuple<_U1, _U2>(), | |
1237 | bool>::type = false> | |
1238 | explicit tuple(allocator_arg_t __tag, const _Alloc& __a, | |
1239 | pair<_U1, _U2>&& __in) | |
1240 | : _Inherited(__tag, __a, std::forward<_U1>(__in.first), | |
1241 | std::forward<_U2>(__in.second)) { } | |
1242 | ||
894d0b15 | 1243 | tuple& |
478490f6 JW |
1244 | operator=(typename conditional<__assignable<const _T1&, const _T2&>(), |
1245 | const tuple&, | |
1246 | const __nonesuch_no_braces&>::type __in) | |
1247 | noexcept(__nothrow_assignable<const _T1&, const _T2&>()) | |
894d0b15 | 1248 | { |
a2c5e1ae | 1249 | this->_M_assign(__in); |
894d0b15 CF |
1250 | return *this; |
1251 | } | |
1252 | ||
ba60f6f9 | 1253 | tuple& |
478490f6 JW |
1254 | operator=(typename conditional<__assignable<_T1, _T2>(), |
1255 | tuple&&, | |
1256 | __nonesuch_no_braces&&>::type __in) | |
1257 | noexcept(__nothrow_assignable<_T1, _T2>()) | |
ba60f6f9 | 1258 | { |
a2c5e1ae | 1259 | this->_M_assign(std::move(__in)); |
ba60f6f9 PC |
1260 | return *this; |
1261 | } | |
1262 | ||
1263 | template<typename _U1, typename _U2> | |
478490f6 JW |
1264 | __enable_if_t<__assignable<const _U1&, const _U2&>(), tuple&> |
1265 | operator=(const tuple<_U1, _U2>& __in) | |
1266 | noexcept(__nothrow_assignable<const _U1&, const _U2&>()) | |
1267 | { | |
a2c5e1ae | 1268 | this->_M_assign(__in); |
ba60f6f9 PC |
1269 | return *this; |
1270 | } | |
1271 | ||
1272 | template<typename _U1, typename _U2> | |
478490f6 JW |
1273 | __enable_if_t<__assignable<_U1, _U2>(), tuple&> |
1274 | operator=(tuple<_U1, _U2>&& __in) | |
1275 | noexcept(__nothrow_assignable<_U1, _U2>()) | |
1276 | { | |
a2c5e1ae | 1277 | this->_M_assign(std::move(__in)); |
ba60f6f9 PC |
1278 | return *this; |
1279 | } | |
1280 | ||
894d0b15 | 1281 | template<typename _U1, typename _U2> |
478490f6 JW |
1282 | __enable_if_t<__assignable<const _U1&, const _U2&>(), tuple&> |
1283 | operator=(const pair<_U1, _U2>& __in) | |
1284 | noexcept(__nothrow_assignable<const _U1&, const _U2&>()) | |
1285 | { | |
9480716c DK |
1286 | this->_M_head(*this) = __in.first; |
1287 | this->_M_tail(*this)._M_head(*this) = __in.second; | |
894d0b15 CF |
1288 | return *this; |
1289 | } | |
ba60f6f9 PC |
1290 | |
1291 | template<typename _U1, typename _U2> | |
478490f6 JW |
1292 | __enable_if_t<__assignable<_U1, _U2>(), tuple&> |
1293 | operator=(pair<_U1, _U2>&& __in) | |
1294 | noexcept(__nothrow_assignable<_U1, _U2>()) | |
1295 | { | |
9480716c DK |
1296 | this->_M_head(*this) = std::forward<_U1>(__in.first); |
1297 | this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second); | |
ba60f6f9 PC |
1298 | return *this; |
1299 | } | |
3e93b275 CF |
1300 | |
1301 | void | |
ff74fd13 | 1302 | swap(tuple& __in) |
a2c5e1ae JW |
1303 | noexcept(__and_<__is_nothrow_swappable<_T1>, |
1304 | __is_nothrow_swappable<_T2>>::value) | |
1aa1114b | 1305 | { _Inherited::_M_swap(__in); } |
894d0b15 CF |
1306 | }; |
1307 | ||
1308 | ||
3c040fa4 JW |
1309 | /// class tuple_size |
1310 | template<typename... _Elements> | |
1311 | struct tuple_size<tuple<_Elements...>> | |
1312 | : public integral_constant<std::size_t, sizeof...(_Elements)> { }; | |
1313 | ||
1314 | #if __cplusplus > 201402L | |
1315 | template <typename _Tp> | |
288695f7 | 1316 | inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value; |
3c040fa4 JW |
1317 | #endif |
1318 | ||
894d0b15 | 1319 | /** |
894d0b15 CF |
1320 | * Recursive case for tuple_element: strip off the first element in |
1321 | * the tuple and retrieve the (i-1)th element of the remaining tuple. | |
894d0b15 | 1322 | */ |
740508be | 1323 | template<std::size_t __i, typename _Head, typename... _Tail> |
894d0b15 CF |
1324 | struct tuple_element<__i, tuple<_Head, _Tail...> > |
1325 | : tuple_element<__i - 1, tuple<_Tail...> > { }; | |
1326 | ||
1327 | /** | |
894d0b15 | 1328 | * Basis case for tuple_element: The first element is the one we're seeking. |
894d0b15 CF |
1329 | */ |
1330 | template<typename _Head, typename... _Tail> | |
1331 | struct tuple_element<0, tuple<_Head, _Tail...> > | |
1332 | { | |
1333 | typedef _Head type; | |
1334 | }; | |
1335 | ||
3c040fa4 JW |
1336 | /** |
1337 | * Error case for tuple_element: invalid index. | |
1338 | */ | |
1339 | template<size_t __i> | |
1340 | struct tuple_element<__i, tuple<>> | |
1341 | { | |
1342 | static_assert(__i < tuple_size<tuple<>>::value, | |
1343 | "tuple index is in range"); | |
1344 | }; | |
137422c8 | 1345 | |
740508be | 1346 | template<std::size_t __i, typename _Head, typename... _Tail> |
af222e74 | 1347 | constexpr _Head& |
173f26ae | 1348 | __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept |
9480716c | 1349 | { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); } |
894d0b15 | 1350 | |
740508be | 1351 | template<std::size_t __i, typename _Head, typename... _Tail> |
af222e74 | 1352 | constexpr const _Head& |
173f26ae | 1353 | __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept |
9480716c | 1354 | { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); } |
894d0b15 | 1355 | |
af222e74 | 1356 | /// Return a reference to the ith element of a tuple. |
740508be | 1357 | template<std::size_t __i, typename... _Elements> |
af222e74 | 1358 | constexpr __tuple_element_t<__i, tuple<_Elements...>>& |
1aa1114b | 1359 | get(tuple<_Elements...>& __t) noexcept |
39e6a690 | 1360 | { return std::__get_helper<__i>(__t); } |
894d0b15 | 1361 | |
af222e74 | 1362 | /// Return a const reference to the ith element of a const tuple. |
740508be | 1363 | template<std::size_t __i, typename... _Elements> |
af222e74 | 1364 | constexpr const __tuple_element_t<__i, tuple<_Elements...>>& |
1aa1114b | 1365 | get(const tuple<_Elements...>& __t) noexcept |
39e6a690 | 1366 | { return std::__get_helper<__i>(__t); } |
894d0b15 | 1367 | |
af222e74 | 1368 | /// Return an rvalue reference to the ith element of a tuple rvalue. |
1aa1114b | 1369 | template<std::size_t __i, typename... _Elements> |
af222e74 | 1370 | constexpr __tuple_element_t<__i, tuple<_Elements...>>&& |
1aa1114b | 1371 | get(tuple<_Elements...>&& __t) noexcept |
af222e74 JW |
1372 | { |
1373 | typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type; | |
1374 | return std::forward<__element_type&&>(std::get<__i>(__t)); | |
1375 | } | |
1aa1114b | 1376 | |
ccbbf8df VV |
1377 | /// Return a const rvalue reference to the ith element of a const tuple rvalue. |
1378 | template<std::size_t __i, typename... _Elements> | |
1379 | constexpr const __tuple_element_t<__i, tuple<_Elements...>>&& | |
1380 | get(const tuple<_Elements...>&& __t) noexcept | |
1381 | { | |
1382 | typedef __tuple_element_t<__i, tuple<_Elements...>> __element_type; | |
1383 | return std::forward<const __element_type&&>(std::get<__i>(__t)); | |
1384 | } | |
1385 | ||
74755c6a | 1386 | #if __cplusplus >= 201402L |
a15f7cb8 ESR |
1387 | |
1388 | #define __cpp_lib_tuples_by_type 201304 | |
1389 | ||
b5a8fed6 | 1390 | template<typename _Head, size_t __i, typename... _Tail> |
af222e74 | 1391 | constexpr _Head& |
b5a8fed6 JW |
1392 | __get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept |
1393 | { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); } | |
1394 | ||
1395 | template<typename _Head, size_t __i, typename... _Tail> | |
af222e74 | 1396 | constexpr const _Head& |
b5a8fed6 JW |
1397 | __get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept |
1398 | { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); } | |
1399 | ||
af222e74 | 1400 | /// Return a reference to the unique element of type _Tp of a tuple. |
b5a8fed6 JW |
1401 | template <typename _Tp, typename... _Types> |
1402 | constexpr _Tp& | |
1403 | get(tuple<_Types...>& __t) noexcept | |
39e6a690 | 1404 | { return std::__get_helper2<_Tp>(__t); } |
b5a8fed6 | 1405 | |
af222e74 | 1406 | /// Return a reference to the unique element of type _Tp of a tuple rvalue. |
b5a8fed6 JW |
1407 | template <typename _Tp, typename... _Types> |
1408 | constexpr _Tp&& | |
1409 | get(tuple<_Types...>&& __t) noexcept | |
af222e74 | 1410 | { return std::forward<_Tp&&>(std::__get_helper2<_Tp>(__t)); } |
b5a8fed6 | 1411 | |
af222e74 | 1412 | /// Return a const reference to the unique element of type _Tp of a tuple. |
b5a8fed6 JW |
1413 | template <typename _Tp, typename... _Types> |
1414 | constexpr const _Tp& | |
1415 | get(const tuple<_Types...>& __t) noexcept | |
39e6a690 | 1416 | { return std::__get_helper2<_Tp>(__t); } |
ccbbf8df VV |
1417 | |
1418 | /// Return a const reference to the unique element of type _Tp of | |
1419 | /// a const tuple rvalue. | |
1420 | template <typename _Tp, typename... _Types> | |
1421 | constexpr const _Tp&& | |
1422 | get(const tuple<_Types...>&& __t) noexcept | |
1423 | { return std::forward<const _Tp&&>(std::__get_helper2<_Tp>(__t)); } | |
b5a8fed6 JW |
1424 | #endif |
1425 | ||
af222e74 JW |
1426 | // This class performs the comparison operations on tuples |
1427 | template<typename _Tp, typename _Up, size_t __i, size_t __size> | |
1428 | struct __tuple_compare | |
894d0b15 | 1429 | { |
af222e74 | 1430 | static constexpr bool |
a7d0c94e | 1431 | __eq(const _Tp& __t, const _Up& __u) |
894d0b15 | 1432 | { |
75e75a08 | 1433 | return bool(std::get<__i>(__t) == std::get<__i>(__u)) |
af222e74 | 1434 | && __tuple_compare<_Tp, _Up, __i + 1, __size>::__eq(__t, __u); |
894d0b15 | 1435 | } |
33ac58d5 | 1436 | |
af222e74 | 1437 | static constexpr bool |
a7d0c94e | 1438 | __less(const _Tp& __t, const _Up& __u) |
894d0b15 | 1439 | { |
75e75a08 | 1440 | return bool(std::get<__i>(__t) < std::get<__i>(__u)) |
af222e74 JW |
1441 | || (!bool(std::get<__i>(__u) < std::get<__i>(__t)) |
1442 | && __tuple_compare<_Tp, _Up, __i + 1, __size>::__less(__t, __u)); | |
894d0b15 CF |
1443 | } |
1444 | }; | |
1445 | ||
af222e74 JW |
1446 | template<typename _Tp, typename _Up, size_t __size> |
1447 | struct __tuple_compare<_Tp, _Up, __size, __size> | |
894d0b15 | 1448 | { |
af222e74 | 1449 | static constexpr bool |
a7d0c94e | 1450 | __eq(const _Tp&, const _Up&) { return true; } |
33ac58d5 | 1451 | |
af222e74 | 1452 | static constexpr bool |
a7d0c94e | 1453 | __less(const _Tp&, const _Up&) { return false; } |
894d0b15 CF |
1454 | }; |
1455 | ||
1456 | template<typename... _TElements, typename... _UElements> | |
a9ba8ba5 | 1457 | constexpr bool |
894d0b15 CF |
1458 | operator==(const tuple<_TElements...>& __t, |
1459 | const tuple<_UElements...>& __u) | |
1460 | { | |
af222e74 JW |
1461 | static_assert(sizeof...(_TElements) == sizeof...(_UElements), |
1462 | "tuple objects can only be compared if they have equal sizes."); | |
1463 | using __compare = __tuple_compare<tuple<_TElements...>, | |
1464 | tuple<_UElements...>, | |
1465 | 0, sizeof...(_TElements)>; | |
1466 | return __compare::__eq(__t, __u); | |
894d0b15 CF |
1467 | } |
1468 | ||
1469 | template<typename... _TElements, typename... _UElements> | |
a9ba8ba5 | 1470 | constexpr bool |
894d0b15 CF |
1471 | operator<(const tuple<_TElements...>& __t, |
1472 | const tuple<_UElements...>& __u) | |
1473 | { | |
af222e74 JW |
1474 | static_assert(sizeof...(_TElements) == sizeof...(_UElements), |
1475 | "tuple objects can only be compared if they have equal sizes."); | |
1476 | using __compare = __tuple_compare<tuple<_TElements...>, | |
1477 | tuple<_UElements...>, | |
1478 | 0, sizeof...(_TElements)>; | |
1479 | return __compare::__less(__t, __u); | |
894d0b15 CF |
1480 | } |
1481 | ||
1482 | template<typename... _TElements, typename... _UElements> | |
fa409833 | 1483 | constexpr bool |
894d0b15 CF |
1484 | operator!=(const tuple<_TElements...>& __t, |
1485 | const tuple<_UElements...>& __u) | |
1486 | { return !(__t == __u); } | |
1487 | ||
1488 | template<typename... _TElements, typename... _UElements> | |
fa409833 | 1489 | constexpr bool |
894d0b15 CF |
1490 | operator>(const tuple<_TElements...>& __t, |
1491 | const tuple<_UElements...>& __u) | |
1492 | { return __u < __t; } | |
1493 | ||
1494 | template<typename... _TElements, typename... _UElements> | |
fa409833 | 1495 | constexpr bool |
894d0b15 CF |
1496 | operator<=(const tuple<_TElements...>& __t, |
1497 | const tuple<_UElements...>& __u) | |
1498 | { return !(__u < __t); } | |
1499 | ||
1500 | template<typename... _TElements, typename... _UElements> | |
fa409833 | 1501 | constexpr bool |
894d0b15 CF |
1502 | operator>=(const tuple<_TElements...>& __t, |
1503 | const tuple<_UElements...>& __u) | |
1504 | { return !(__t < __u); } | |
1505 | ||
1506 | // NB: DR 705. | |
1507 | template<typename... _Elements> | |
fae3f459 | 1508 | constexpr tuple<typename __decay_and_strip<_Elements>::__type...> |
894d0b15 CF |
1509 | make_tuple(_Elements&&... __args) |
1510 | { | |
1511 | typedef tuple<typename __decay_and_strip<_Elements>::__type...> | |
1512 | __result_type; | |
1513 | return __result_type(std::forward<_Elements>(__args)...); | |
1514 | } | |
1515 | ||
cb2ef49e JW |
1516 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1517 | // 2275. Why is forward_as_tuple not constexpr? | |
74755c6a | 1518 | /// std::forward_as_tuple |
5e108459 | 1519 | template<typename... _Elements> |
cb2ef49e | 1520 | constexpr tuple<_Elements&&...> |
1aa1114b | 1521 | forward_as_tuple(_Elements&&... __args) noexcept |
00e9a944 | 1522 | { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); } |
5e108459 | 1523 | |
af222e74 | 1524 | template<size_t, typename, typename, size_t> |
ac65b7d2 DK |
1525 | struct __make_tuple_impl; |
1526 | ||
af222e74 | 1527 | template<size_t _Idx, typename _Tuple, typename... _Tp, size_t _Nm> |
ac65b7d2 | 1528 | struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm> |
af222e74 JW |
1529 | : __make_tuple_impl<_Idx + 1, |
1530 | tuple<_Tp..., __tuple_element_t<_Idx, _Tuple>>, | |
1531 | _Tuple, _Nm> | |
1532 | { }; | |
894d0b15 | 1533 | |
ac65b7d2 DK |
1534 | template<std::size_t _Nm, typename _Tuple, typename... _Tp> |
1535 | struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm> | |
894d0b15 | 1536 | { |
ac65b7d2 DK |
1537 | typedef tuple<_Tp...> __type; |
1538 | }; | |
894d0b15 | 1539 | |
ac65b7d2 DK |
1540 | template<typename _Tuple> |
1541 | struct __do_make_tuple | |
af222e74 | 1542 | : __make_tuple_impl<0, tuple<>, _Tuple, std::tuple_size<_Tuple>::value> |
ac65b7d2 DK |
1543 | { }; |
1544 | ||
1545 | // Returns the std::tuple equivalent of a tuple-like type. | |
1546 | template<typename _Tuple> | |
1547 | struct __make_tuple | |
6791489e | 1548 | : public __do_make_tuple<__remove_cvref_t<_Tuple>> |
ac65b7d2 DK |
1549 | { }; |
1550 | ||
1551 | // Combines several std::tuple's into a single one. | |
1552 | template<typename...> | |
1553 | struct __combine_tuples; | |
1554 | ||
1555 | template<> | |
1556 | struct __combine_tuples<> | |
1557 | { | |
1558 | typedef tuple<> __type; | |
1559 | }; | |
1560 | ||
1561 | template<typename... _Ts> | |
1562 | struct __combine_tuples<tuple<_Ts...>> | |
894d0b15 | 1563 | { |
ac65b7d2 DK |
1564 | typedef tuple<_Ts...> __type; |
1565 | }; | |
1566 | ||
1567 | template<typename... _T1s, typename... _T2s, typename... _Rem> | |
1568 | struct __combine_tuples<tuple<_T1s...>, tuple<_T2s...>, _Rem...> | |
1569 | { | |
1570 | typedef typename __combine_tuples<tuple<_T1s..., _T2s...>, | |
1571 | _Rem...>::__type __type; | |
1572 | }; | |
1573 | ||
1574 | // Computes the result type of tuple_cat given a set of tuple-like types. | |
1575 | template<typename... _Tpls> | |
1576 | struct __tuple_cat_result | |
1577 | { | |
1578 | typedef typename __combine_tuples | |
1579 | <typename __make_tuple<_Tpls>::__type...>::__type __type; | |
1580 | }; | |
1581 | ||
1582 | // Helper to determine the index set for the first tuple-like | |
1583 | // type of a given set. | |
1584 | template<typename...> | |
1585 | struct __make_1st_indices; | |
1586 | ||
1587 | template<> | |
1588 | struct __make_1st_indices<> | |
1589 | { | |
1590 | typedef std::_Index_tuple<> __type; | |
1591 | }; | |
1592 | ||
1593 | template<typename _Tp, typename... _Tpls> | |
1594 | struct __make_1st_indices<_Tp, _Tpls...> | |
1595 | { | |
1596 | typedef typename std::_Build_index_tuple<std::tuple_size< | |
1597 | typename std::remove_reference<_Tp>::type>::value>::__type __type; | |
1598 | }; | |
1599 | ||
1600 | // Performs the actual concatenation by step-wise expanding tuple-like | |
1601 | // objects into the elements, which are finally forwarded into the | |
1602 | // result tuple. | |
1603 | template<typename _Ret, typename _Indices, typename... _Tpls> | |
1604 | struct __tuple_concater; | |
1605 | ||
1606 | template<typename _Ret, std::size_t... _Is, typename _Tp, typename... _Tpls> | |
1607 | struct __tuple_concater<_Ret, std::_Index_tuple<_Is...>, _Tp, _Tpls...> | |
1608 | { | |
1609 | template<typename... _Us> | |
9480716c | 1610 | static constexpr _Ret |
ac65b7d2 DK |
1611 | _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us) |
1612 | { | |
1613 | typedef typename __make_1st_indices<_Tpls...>::__type __idx; | |
1614 | typedef __tuple_concater<_Ret, __idx, _Tpls...> __next; | |
1615 | return __next::_S_do(std::forward<_Tpls>(__tps)..., | |
1616 | std::forward<_Us>(__us)..., | |
1617 | std::get<_Is>(std::forward<_Tp>(__tp))...); | |
1618 | } | |
1619 | }; | |
1620 | ||
1621 | template<typename _Ret> | |
1622 | struct __tuple_concater<_Ret, std::_Index_tuple<>> | |
1623 | { | |
1624 | template<typename... _Us> | |
9480716c | 1625 | static constexpr _Ret |
ac65b7d2 DK |
1626 | _S_do(_Us&&... __us) |
1627 | { | |
1628 | return _Ret(std::forward<_Us>(__us)...); | |
1629 | } | |
1630 | }; | |
1631 | ||
c0ffa2ba | 1632 | /// tuple_cat |
9480716c DK |
1633 | template<typename... _Tpls, typename = typename |
1634 | enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type> | |
1635 | constexpr auto | |
ac65b7d2 | 1636 | tuple_cat(_Tpls&&... __tpls) |
9480716c | 1637 | -> typename __tuple_cat_result<_Tpls...>::__type |
ac65b7d2 DK |
1638 | { |
1639 | typedef typename __tuple_cat_result<_Tpls...>::__type __ret; | |
1640 | typedef typename __make_1st_indices<_Tpls...>::__type __idx; | |
1641 | typedef __tuple_concater<__ret, __idx, _Tpls...> __concater; | |
1642 | return __concater::_S_do(std::forward<_Tpls>(__tpls)...); | |
894d0b15 CF |
1643 | } |
1644 | ||
cb2ef49e JW |
1645 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1646 | // 2301. Why is tie not constexpr? | |
c0ffa2ba | 1647 | /// tie |
894d0b15 | 1648 | template<typename... _Elements> |
cb2ef49e | 1649 | constexpr tuple<_Elements&...> |
1aa1114b | 1650 | tie(_Elements&... __args) noexcept |
894d0b15 CF |
1651 | { return tuple<_Elements&...>(__args...); } |
1652 | ||
c0ffa2ba | 1653 | /// swap |
3e93b275 | 1654 | template<typename... _Elements> |
6b9539e2 DK |
1655 | inline |
1656 | #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 | |
1657 | // Constrained free swap overload, see p0185r1 | |
1658 | typename enable_if<__and_<__is_swappable<_Elements>...>::value | |
1659 | >::type | |
1660 | #else | |
1661 | void | |
1662 | #endif | |
3e93b275 | 1663 | swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y) |
1aa1114b | 1664 | noexcept(noexcept(__x.swap(__y))) |
3e93b275 CF |
1665 | { __x.swap(__y); } |
1666 | ||
a2863bde VV |
1667 | #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 |
1668 | template<typename... _Elements> | |
a2863bde VV |
1669 | typename enable_if<!__and_<__is_swappable<_Elements>...>::value>::type |
1670 | swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete; | |
1671 | #endif | |
1672 | ||
894d0b15 | 1673 | // A class (and instance) which can be used in 'tie' when an element |
288695f7 DK |
1674 | // of a tuple is not required. |
1675 | // _GLIBCXX14_CONSTEXPR | |
1676 | // 2933. PR for LWG 2773 could be clearer | |
894d0b15 CF |
1677 | struct _Swallow_assign |
1678 | { | |
1679 | template<class _Tp> | |
288695f7 | 1680 | _GLIBCXX14_CONSTEXPR const _Swallow_assign& |
cff90044 | 1681 | operator=(const _Tp&) const |
894d0b15 CF |
1682 | { return *this; } |
1683 | }; | |
1684 | ||
288695f7 DK |
1685 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1686 | // 2773. Making std::ignore constexpr | |
1687 | _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{}; | |
5e108459 | 1688 | |
b8214660 JW |
1689 | /// Partial specialization for tuples |
1690 | template<typename... _Types, typename _Alloc> | |
1691 | struct uses_allocator<tuple<_Types...>, _Alloc> : true_type { }; | |
1692 | ||
5e108459 PC |
1693 | // See stl_pair.h... |
1694 | template<class _T1, class _T2> | |
62b547b5 JW |
1695 | template<typename... _Args1, typename... _Args2> |
1696 | inline | |
1697 | pair<_T1, _T2>:: | |
1698 | pair(piecewise_construct_t, | |
1699 | tuple<_Args1...> __first, tuple<_Args2...> __second) | |
1700 | : pair(__first, __second, | |
1701 | typename _Build_index_tuple<sizeof...(_Args1)>::__type(), | |
1702 | typename _Build_index_tuple<sizeof...(_Args2)>::__type()) | |
1703 | { } | |
5e108459 PC |
1704 | |
1705 | template<class _T1, class _T2> | |
62b547b5 JW |
1706 | template<typename... _Args1, std::size_t... _Indexes1, |
1707 | typename... _Args2, std::size_t... _Indexes2> | |
1708 | inline | |
1709 | pair<_T1, _T2>:: | |
1710 | pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2, | |
1711 | _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>) | |
1712 | : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...), | |
1713 | second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...) | |
1714 | { } | |
53dc5044 | 1715 | |
81c7cf71 | 1716 | #if __cplusplus >= 201703L |
3e9f67e6 JW |
1717 | # define __cpp_lib_apply 201603 |
1718 | ||
1719 | template <typename _Fn, typename _Tuple, size_t... _Idx> | |
1720 | constexpr decltype(auto) | |
1721 | __apply_impl(_Fn&& __f, _Tuple&& __t, index_sequence<_Idx...>) | |
1722 | { | |
1723 | return std::__invoke(std::forward<_Fn>(__f), | |
1724 | std::get<_Idx>(std::forward<_Tuple>(__t))...); | |
1725 | } | |
1726 | ||
1727 | template <typename _Fn, typename _Tuple> | |
1728 | constexpr decltype(auto) | |
1729 | apply(_Fn&& __f, _Tuple&& __t) | |
1730 | { | |
81c7cf71 JW |
1731 | using _Indices |
1732 | = make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>; | |
285ee2fb JW |
1733 | return std::__apply_impl(std::forward<_Fn>(__f), |
1734 | std::forward<_Tuple>(__t), | |
1735 | _Indices{}); | |
3e9f67e6 | 1736 | } |
ca1ab6be | 1737 | |
24299f65 VV |
1738 | #define __cpp_lib_make_from_tuple 201606 |
1739 | ||
ca1ab6be VV |
1740 | template <typename _Tp, typename _Tuple, size_t... _Idx> |
1741 | constexpr _Tp | |
1742 | __make_from_tuple_impl(_Tuple&& __t, index_sequence<_Idx...>) | |
24299f65 | 1743 | { return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...); } |
ca1ab6be VV |
1744 | |
1745 | template <typename _Tp, typename _Tuple> | |
1746 | constexpr _Tp | |
1747 | make_from_tuple(_Tuple&& __t) | |
1748 | { | |
1749 | return __make_from_tuple_impl<_Tp>( | |
1750 | std::forward<_Tuple>(__t), | |
1751 | make_index_sequence<tuple_size_v<decay_t<_Tuple>>>{}); | |
1752 | } | |
3e9f67e6 JW |
1753 | #endif // C++17 |
1754 | ||
c0ffa2ba BK |
1755 | /// @} |
1756 | ||
12ffa228 | 1757 | _GLIBCXX_END_NAMESPACE_VERSION |
c0ffa2ba | 1758 | } // namespace std |
af13a7a6 | 1759 | |
734f5023 | 1760 | #endif // C++11 |
57317d2a | 1761 | |
4514bed6 | 1762 | #endif // _GLIBCXX_TUPLE |