blob: 251443eced7379d8214f8563b78558fa78c8cc60 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===--------------------------- tuple ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_TUPLE
12#define _LIBCPP_TUPLE
13
14/*
15 tuple synopsis
16
17namespace std
18{
19
20template <class... T>
21class tuple {
22public:
23 constexpr tuple();
Marshall Clowda0a0e82013-07-22 16:02:1924 explicit tuple(const T&...); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1625 template <class... U>
Marshall Clowda0a0e82013-07-22 16:02:1926 explicit tuple(U&&...); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1627 tuple(const tuple&) = default;
Howard Hinnanta5e01212011-05-27 19:08:1828 tuple(tuple&&) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:1629 template <class... U>
Marshall Clowda0a0e82013-07-22 16:02:1930 tuple(const tuple<U...>&); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1631 template <class... U>
Marshall Clowda0a0e82013-07-22 16:02:1932 tuple(tuple<U...>&&); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1633 template <class U1, class U2>
Marshall Clowda0a0e82013-07-22 16:02:1934 tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1635 template <class U1, class U2>
Marshall Clowda0a0e82013-07-22 16:02:1936 tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1637
38 // allocator-extended constructors
39 template <class Alloc>
40 tuple(allocator_arg_t, const Alloc& a);
41 template <class Alloc>
42 tuple(allocator_arg_t, const Alloc& a, const T&...);
43 template <class Alloc, class... U>
44 tuple(allocator_arg_t, const Alloc& a, U&&...);
45 template <class Alloc>
46 tuple(allocator_arg_t, const Alloc& a, const tuple&);
47 template <class Alloc>
48 tuple(allocator_arg_t, const Alloc& a, tuple&&);
49 template <class Alloc, class... U>
50 tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
51 template <class Alloc, class... U>
52 tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
53 template <class Alloc, class U1, class U2>
54 tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
55 template <class Alloc, class U1, class U2>
56 tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
57
58 tuple& operator=(const tuple&);
Howard Hinnanta5e01212011-05-27 19:08:1859 tuple&
60 operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...));
Howard Hinnantbc8d3f92010-05-11 19:42:1661 template <class... U>
62 tuple& operator=(const tuple<U...>&);
63 template <class... U>
64 tuple& operator=(tuple<U...>&&);
65 template <class U1, class U2>
66 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
67 template <class U1, class U2>
68 tuple& operator=(pair<U1, U2>&&); //iffsizeof...(T) == 2
69
Howard Hinnanta5e01212011-05-27 19:08:1870 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
Howard Hinnantbc8d3f92010-05-11 19:42:1671};
72
73const unspecified ignore;
74
Marshall Clowda0a0e82013-07-22 16:02:1975template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clow1d927e32013-10-05 18:46:3776template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clow8e554d92014-02-25 16:11:4677template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clowda0a0e82013-07-22 16:02:1978template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier5839fed2016-07-18 00:35:5679
80// [tuple.apply], calling a function with a tuple of arguments:
81template <class F, class Tuple>
82 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
83template <class T, class Tuple>
84 constexpr T make_from_tuple(Tuple&& t); // C++17
85
Howard Hinnantbc8d3f92010-05-11 19:42:1686// 20.4.1.4, tuple helper classes:
Eric Fiselierf9a20c22016-11-13 20:43:5087template <class T> class tuple_size;
Howard Hinnantbc8d3f92010-05-11 19:42:1688template <class... T> class tuple_size<tuple<T...>>;
Eric Fiselier5839fed2016-07-18 00:35:5689template <class T>
90 constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Marshall Clowa6607572015-11-19 19:45:2991template <size_t I, class T> class tuple_element; // undefined
92template <size_t I, class... T> class tuple_element<I, tuple<T...>>;
93template <size_t I, class T>
94 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1695
96// 20.4.1.5, element access:
Marshall Clowa6607572015-11-19 19:45:2997template <size_t I, class... T>
Howard Hinnanta5e01212011-05-27 19:08:1898 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow8fc4f5a2013-07-17 18:25:3699 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clowa6607572015-11-19 19:45:29100template <size_t I, class... T>
101 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow8fc4f5a2013-07-17 18:25:36102 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clowa6607572015-11-19 19:45:29103template <size_t I, class... T>
Howard Hinnanta5e01212011-05-27 19:08:18104 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow8fc4f5a2013-07-17 18:25:36105 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier199bee02015-12-18 00:36:55106template <size_t I, class... T>
107 const typename tuple_element<I, tuple<T...>>::type&&
108 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16109
Marshall Clowe8029e52013-07-13 02:54:05110template <class T1, class... T>
111 constexpr T1& get(tuple<T...>&) noexcept; // C++14
112template <class T1, class... T>
Marshall Clowa6607572015-11-19 19:45:29113 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05114template <class T1, class... T>
115 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier199bee02015-12-18 00:36:55116template <class T1, class... T>
117 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clowe8029e52013-07-13 02:54:05118
Howard Hinnantbc8d3f92010-05-11 19:42:16119// 20.4.1.6, relational operators:
Marshall Clowda0a0e82013-07-22 16:02:19120template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
121template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
122template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
123template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
124template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
125template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16126
127template <class... Types, class Alloc>
128 struct uses_allocator<tuple<Types...>, Alloc>;
129
130template <class... Types>
Howard Hinnanta5e01212011-05-27 19:08:18131 void
132 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16133
Howard Hinnantbc8d3f92010-05-11 19:42:16134} // std
135
136*/
137
138#include <__config>
139#include <__tuple>
140#include <cstddef>
Howard Hinnantbc8d3f92010-05-11 19:42:16141#include <type_traits>
Howard Hinnant6cc99fa2011-12-19 17:58:44142#include <__functional_base>
143#include <utility>
Howard Hinnantbc8d3f92010-05-11 19:42:16144
Howard Hinnant08e17472011-10-17 20:05:10145#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16146#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10147#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16148
149_LIBCPP_BEGIN_NAMESPACE_STD
150
151#ifndef _LIBCPP_HAS_NO_VARIADICS
152
Marshall Clow50fe0c72014-03-03 06:18:11153
Howard Hinnantbc8d3f92010-05-11 19:42:16154// __tuple_leaf
155
Eric Fiselier3a0e4302015-06-13 07:08:02156template <size_t _Ip, class _Hp,
157 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd4cf2152011-12-11 20:31:33158 >
Howard Hinnantbc8d3f92010-05-11 19:42:16159class __tuple_leaf;
160
161template <size_t _Ip, class _Hp, bool _Ep>
Howard Hinnantee6ccd02010-09-23 18:58:28162inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16163void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnanta5e01212011-05-27 19:08:18164 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16165{
166 swap(__x.get(), __y.get());
167}
168
169template <size_t _Ip, class _Hp, bool>
170class __tuple_leaf
171{
172 _Hp value;
173
Eric Fiselier9c747b92016-07-20 02:57:39174 template <class _Tp>
175 static constexpr bool __can_bind_reference() {
176 using _RawTp = typename remove_reference<_Tp>::type;
177 using _RawHp = typename remove_reference<_Hp>::type;
178 using _CheckLValueArg = integral_constant<bool,
179 is_lvalue_reference<_Tp>::value
180 || is_same<_RawTp, reference_wrapper<_RawHp>>::value
181 || is_same<_RawTp, reference_wrapper<typename remove_const<_RawHp>::type>>::value
182 >;
183 return !is_reference<_Hp>::value
184 || (is_lvalue_reference<_Hp>::value && _CheckLValueArg::value)
185 || (is_rvalue_reference<_Hp>::value && !is_lvalue_reference<_Tp>::value);
186 }
187
Howard Hinnantbc8d3f92010-05-11 19:42:16188 __tuple_leaf& operator=(const __tuple_leaf&);
189public:
Howard Hinnant4eebfc32012-07-06 20:50:27190 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
191 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value()
Howard Hinnantbc8d3f92010-05-11 19:42:16192 {static_assert(!is_reference<_Hp>::value,
193 "Attempted to default construct a reference element in a tuple");}
194
195 template <class _Alloc>
196 _LIBCPP_INLINE_VISIBILITY
197 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
198 : value()
199 {static_assert(!is_reference<_Hp>::value,
200 "Attempted to default construct a reference element in a tuple");}
201
202 template <class _Alloc>
203 _LIBCPP_INLINE_VISIBILITY
204 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
205 : value(allocator_arg_t(), __a)
206 {static_assert(!is_reference<_Hp>::value,
207 "Attempted to default construct a reference element in a tuple");}
208
209 template <class _Alloc>
210 _LIBCPP_INLINE_VISIBILITY
211 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
212 : value(__a)
213 {static_assert(!is_reference<_Hp>::value,
214 "Attempted to default construct a reference element in a tuple");}
215
Howard Hinnante049cc52010-09-27 17:54:17216 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34217 class = typename enable_if<
218 __lazy_and<
219 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
220 , is_constructible<_Hp, _Tp>
221 >::value
222 >::type
223 >
Marshall Clowda0a0e82013-07-22 16:02:19224 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48225 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19226 : value(_VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39227 {static_assert(__can_bind_reference<_Tp>(),
Howard Hinnantbc8d3f92010-05-11 19:42:16228 "Attempted to construct a reference element in a tuple with an rvalue");}
229
230 template <class _Tp, class _Alloc>
231 _LIBCPP_INLINE_VISIBILITY
232 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19233 : value(_VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39234 {static_assert(__can_bind_reference<_Tp>(),
Howard Hinnantbc8d3f92010-05-11 19:42:16235 "Attempted to construct a reference element in a tuple with an rvalue");}
236
237 template <class _Tp, class _Alloc>
238 _LIBCPP_INLINE_VISIBILITY
239 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19240 : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselier9c747b92016-07-20 02:57:39241 {static_assert(!is_reference<_Hp>::value,
242 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16243
244 template <class _Tp, class _Alloc>
245 _LIBCPP_INLINE_VISIBILITY
246 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19247 : value(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselier9c747b92016-07-20 02:57:39248 {static_assert(!is_reference<_Hp>::value,
249 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantbc8d3f92010-05-11 19:42:16250
Marshall Clow398c9d82014-04-21 23:48:09251 __tuple_leaf(const __tuple_leaf& __t) = default;
252 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16253
254 template <class _Tp>
255 _LIBCPP_INLINE_VISIBILITY
256 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48257 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16258 {
Howard Hinnant0949eed2011-06-30 21:18:19259 value = _VSTD::forward<_Tp>(__t);
Howard Hinnantbc8d3f92010-05-11 19:42:16260 return *this;
261 }
262
263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18264 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16265 {
Howard Hinnant0949eed2011-06-30 21:18:19266 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16267 return 0;
268 }
269
Marshall Clowda0a0e82013-07-22 16:02:19270 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;}
271 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;}
Howard Hinnantbc8d3f92010-05-11 19:42:16272};
273
274template <size_t _Ip, class _Hp>
275class __tuple_leaf<_Ip, _Hp, true>
276 : private _Hp
277{
278
279 __tuple_leaf& operator=(const __tuple_leaf&);
280public:
Howard Hinnant4eebfc32012-07-06 20:50:27281 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
282 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16283
284 template <class _Alloc>
285 _LIBCPP_INLINE_VISIBILITY
286 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
287
288 template <class _Alloc>
289 _LIBCPP_INLINE_VISIBILITY
290 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
291 : _Hp(allocator_arg_t(), __a) {}
292
293 template <class _Alloc>
294 _LIBCPP_INLINE_VISIBILITY
295 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
296 : _Hp(__a) {}
297
Howard Hinnante049cc52010-09-27 17:54:17298 template <class _Tp,
Eric Fiselier9020c082014-07-24 18:48:34299 class = typename enable_if<
300 __lazy_and<
301 __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>>
302 , is_constructible<_Hp, _Tp>
303 >::value
304 >::type
305 >
Marshall Clowda0a0e82013-07-22 16:02:19306 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48307 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnant0949eed2011-06-30 21:18:19308 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16309
310 template <class _Tp, class _Alloc>
311 _LIBCPP_INLINE_VISIBILITY
312 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19313 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16314
315 template <class _Tp, class _Alloc>
316 _LIBCPP_INLINE_VISIBILITY
317 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19318 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16319
320 template <class _Tp, class _Alloc>
321 _LIBCPP_INLINE_VISIBILITY
322 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19323 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16324
Eric Fiselier9020c082014-07-24 18:48:34325 __tuple_leaf(__tuple_leaf const &) = default;
326 __tuple_leaf(__tuple_leaf &&) = default;
327
Howard Hinnantbc8d3f92010-05-11 19:42:16328 template <class _Tp>
329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16330 __tuple_leaf&
Howard Hinnant74f26f22012-07-06 21:53:48331 operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16332 {
Howard Hinnant0949eed2011-06-30 21:18:19333 _Hp::operator=(_VSTD::forward<_Tp>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16334 return *this;
335 }
336
Howard Hinnanta5e01212011-05-27 19:08:18337 _LIBCPP_INLINE_VISIBILITY
338 int
339 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16340 {
Howard Hinnant0949eed2011-06-30 21:18:19341 _VSTD::swap(*this, __t);
Howard Hinnantbc8d3f92010-05-11 19:42:16342 return 0;
343 }
344
Marshall Clowda0a0e82013-07-22 16:02:19345 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
346 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:16347};
348
Howard Hinnantee6ccd02010-09-23 18:58:28349template <class ..._Tp>
350_LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48351void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16352
Eric Fiselier55ad3ac2016-04-15 03:29:40353template <class ..._Tp>
354struct __lazy_all : __all<_Tp::value...> {};
355
Marshall Clowbbc7c742014-10-15 10:33:02356template <class _Tp>
357struct __all_default_constructible;
Howard Hinnanta5e01212011-05-27 19:08:18358
Marshall Clowbbc7c742014-10-15 10:33:02359template <class ..._Tp>
360struct __all_default_constructible<__tuple_types<_Tp...>>
361 : __all<is_default_constructible<_Tp>::value...>
362{ };
Howard Hinnanta5e01212011-05-27 19:08:18363
Howard Hinnantbc8d3f92010-05-11 19:42:16364// __tuple_impl
365
366template<class _Indx, class ..._Tp> struct __tuple_impl;
367
368template<size_t ..._Indx, class ..._Tp>
369struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
370 : public __tuple_leaf<_Indx, _Tp>...
371{
Howard Hinnant5394c1e2012-07-06 20:39:45372 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27373 _LIBCPP_CONSTEXPR __tuple_impl()
374 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45375
Howard Hinnantbc8d3f92010-05-11 19:42:16376 template <size_t ..._Uf, class ..._Tf,
377 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:19378 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16379 explicit
380 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
381 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant74f26f22012-07-06 21:53:48382 _Up&&... __u)
383 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
384 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnant0949eed2011-06-30 21:18:19385 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16386 __tuple_leaf<_Ul, _Tl>()...
387 {}
388
389 template <class _Alloc, size_t ..._Uf, class ..._Tf,
390 size_t ..._Ul, class ..._Tl, class ..._Up>
Howard Hinnantee6ccd02010-09-23 18:58:28391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16392 explicit
393 __tuple_impl(allocator_arg_t, const _Alloc& __a,
394 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
395 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
396 _Up&&... __u) :
397 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19398 _VSTD::forward<_Up>(__u))...,
Howard Hinnantbc8d3f92010-05-11 19:42:16399 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
400 {}
401
402 template <class _Tuple,
403 class = typename enable_if
404 <
Howard Hinnant99324892013-04-14 00:01:13405 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16406 >::type
407 >
Marshall Clowda0a0e82013-07-22 16:02:19408 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48409 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
410 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnant0949eed2011-06-30 21:18:19411 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
412 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16413 {}
414
415 template <class _Alloc, class _Tuple,
416 class = typename enable_if
417 <
Eric Fiselier95526d32016-04-19 01:19:25418 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantbc8d3f92010-05-11 19:42:16419 >::type
420 >
Howard Hinnantee6ccd02010-09-23 18:58:28421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16422 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
423 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant324bb032010-08-22 00:02:43424 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnant0949eed2011-06-30 21:18:19425 _VSTD::forward<typename tuple_element<_Indx,
426 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantbc8d3f92010-05-11 19:42:16427 {}
428
429 template <class _Tuple>
Howard Hinnantee6ccd02010-09-23 18:58:28430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16431 typename enable_if
432 <
Howard Hinnantf83417b2011-01-24 16:07:25433 __tuple_assignable<_Tuple, tuple<_Tp...> >::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16434 __tuple_impl&
435 >::type
Howard Hinnant74f26f22012-07-06 21:53:48436 operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
437 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16438 {
Howard Hinnant0949eed2011-06-30 21:18:19439 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
440 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16441 return *this;
442 }
443
Howard Hinnant3de50862013-11-06 17:45:43444 __tuple_impl(const __tuple_impl&) = default;
445 __tuple_impl(__tuple_impl&&) = default;
446
447 _LIBCPP_INLINE_VISIBILITY
448 __tuple_impl&
449 operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
450 {
451 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
452 return *this;
453 }
454
455 _LIBCPP_INLINE_VISIBILITY
456 __tuple_impl&
457 operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
458 {
459 __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
460 return *this;
461 }
Howard Hinnant28484442012-02-15 20:13:52462
Howard Hinnantee6ccd02010-09-23 18:58:28463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16464 void swap(__tuple_impl& __t)
Howard Hinnanta5e01212011-05-27 19:08:18465 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16466 {
467 __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
468 }
469};
470
Eric Fiselierd5019332016-04-15 18:05:59471
Eric Fiselierd5019332016-04-15 18:05:59472
Howard Hinnantbc8d3f92010-05-11 19:42:16473template <class ..._Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34474class _LIBCPP_TYPE_VIS_ONLY tuple
Howard Hinnantbc8d3f92010-05-11 19:42:16475{
476 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
477
478 base base_;
479
Eric Fiselierd5019332016-04-15 18:05:59480 template <class ..._Args>
481 struct _PackExpandsToThisTuple : false_type {};
482
483 template <class _Arg>
484 struct _PackExpandsToThisTuple<_Arg>
485 : is_same<typename __uncvref<_Arg>::type, tuple> {};
486
487 template <bool _MaybeEnable, class _Dummy = void>
488 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
489
490 template <class _Dummy>
491 struct _CheckArgsConstructor<true, _Dummy>
492 {
493 template <class ..._Args>
Eric Fiseliere1445fd2016-07-25 04:32:07494 static constexpr bool __enable_default() {
495 return __all<is_default_constructible<_Args>::value...>::value;
496 }
497
498 template <class ..._Args>
Eric Fiselierd5019332016-04-15 18:05:59499 static constexpr bool __enable_explicit() {
500 return
501 __tuple_constructible<
502 tuple<_Args...>,
503 typename __make_tuple_types<tuple,
504 sizeof...(_Args) < sizeof...(_Tp) ?
505 sizeof...(_Args) :
506 sizeof...(_Tp)>::type
507 >::value &&
508 !__tuple_convertible<
509 tuple<_Args...>,
510 typename __make_tuple_types<tuple,
511 sizeof...(_Args) < sizeof...(_Tp) ?
512 sizeof...(_Args) :
513 sizeof...(_Tp)>::type
514 >::value &&
515 __all_default_constructible<
516 typename __make_tuple_types<tuple, sizeof...(_Tp),
517 sizeof...(_Args) < sizeof...(_Tp) ?
518 sizeof...(_Args) :
519 sizeof...(_Tp)>::type
520 >::value;
521 }
522
523 template <class ..._Args>
524 static constexpr bool __enable_implicit() {
525 return
526 __tuple_convertible<
527 tuple<_Args...>,
528 typename __make_tuple_types<tuple,
529 sizeof...(_Args) < sizeof...(_Tp) ?
530 sizeof...(_Args) :
531 sizeof...(_Tp)>::type
532 >::value &&
533 __all_default_constructible<
534 typename __make_tuple_types<tuple, sizeof...(_Tp),
535 sizeof...(_Args) < sizeof...(_Tp) ?
536 sizeof...(_Args) :
537 sizeof...(_Tp)>::type
538 >::value;
539 }
540 };
541
542 template <bool _MaybeEnable,
543 bool = sizeof...(_Tp) == 1,
544 class _Dummy = void>
545 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
546
547 template <class _Dummy>
548 struct _CheckTupleLikeConstructor<true, false, _Dummy>
549 {
550 template <class _Tuple>
551 static constexpr bool __enable_implicit() {
552 return __tuple_convertible<_Tuple, tuple>::value;
553 }
554
555 template <class _Tuple>
556 static constexpr bool __enable_explicit() {
557 return __tuple_constructible<_Tuple, tuple>::value
558 && !__tuple_convertible<_Tuple, tuple>::value;
559 }
560 };
561
562 template <class _Dummy>
563 struct _CheckTupleLikeConstructor<true, true, _Dummy>
564 {
565 // This trait is used to disable the tuple-like constructor when
566 // the UTypes... constructor should be selected instead.
567 // See LWG issue #2549.
568 template <class _Tuple>
569 using _PreferTupleLikeConstructor = __lazy_or<
570 // Don't attempt the two checks below if the tuple we are given
571 // has the same type as this tuple.
572 is_same<typename __uncvref<_Tuple>::type, tuple>,
573 __lazy_and<
574 __lazy_not<is_constructible<_Tp..., _Tuple>>,
575 __lazy_not<is_convertible<_Tuple, _Tp...>>
576 >
577 >;
578
579 template <class _Tuple>
580 static constexpr bool __enable_implicit() {
581 return __lazy_and<
582 __tuple_convertible<_Tuple, tuple>,
583 _PreferTupleLikeConstructor<_Tuple>
584 >::value;
585 }
586
587 template <class _Tuple>
588 static constexpr bool __enable_explicit() {
589 return __lazy_and<
590 __tuple_constructible<_Tuple, tuple>,
591 _PreferTupleLikeConstructor<_Tuple>,
592 __lazy_not<__tuple_convertible<_Tuple, tuple>>
593 >::value;
594 }
595 };
596
Marshall Clow8fc4f5a2013-07-17 18:25:36597 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04598 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36599 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04600 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow8fc4f5a2013-07-17 18:25:36601 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantec3773c2011-12-01 20:21:04602 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55603 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
604 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16605public:
606
Eric Fiselierda1818a2015-02-21 02:30:41607 template <bool _Dummy = true, class = typename enable_if<
Eric Fiseliere1445fd2016-07-25 04:32:07608 _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>()
Marshall Clowbbc7c742014-10-15 10:33:02609 >::type>
Howard Hinnantee6ccd02010-09-23 18:58:28610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27611 _LIBCPP_CONSTEXPR tuple()
612 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant5394c1e2012-07-06 20:39:45613
Eric Fiselier4be71c62016-07-25 02:36:42614 tuple(tuple const&) = default;
615 tuple(tuple&&) = default;
616
Eric Fiselier55ad3ac2016-04-15 03:29:40617 template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
618 __lazy_and<
Eric Fiselierfa5a1052016-06-21 23:19:13619 is_same<allocator_arg_t, _AllocArgT>,
Eric Fiselier55ad3ac2016-04-15 03:29:40620 __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
621 >::value
622 >::type>
623 _LIBCPP_INLINE_VISIBILITY
624 tuple(_AllocArgT, _Alloc const& __a)
625 : base_(allocator_arg_t(), __a,
626 __tuple_indices<>(), __tuple_types<>(),
627 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
628 __tuple_types<_Tp...>()) {}
629
Eric Fiselier95526d32016-04-19 01:19:25630 template <bool _Dummy = true,
631 typename enable_if
632 <
633 _CheckArgsConstructor<
634 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31635 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25636 bool
637 >::type = false
638 >
Marshall Clowda0a0e82013-07-22 16:02:19639 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier95526d32016-04-19 01:19:25640 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16641 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
642 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
643 typename __make_tuple_indices<0>::type(),
644 typename __make_tuple_types<tuple, 0>::type(),
645 __t...
646 ) {}
647
Eric Fiselier95526d32016-04-19 01:19:25648 template <bool _Dummy = true,
649 typename enable_if
650 <
651 _CheckArgsConstructor<
652 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31653 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25654 bool
655 >::type = false
656 >
657 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
658 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
659 : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
660 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
661 typename __make_tuple_indices<0>::type(),
662 typename __make_tuple_types<tuple, 0>::type(),
663 __t...
664 ) {}
665
666 template <class _Alloc, bool _Dummy = true,
667 typename enable_if
668 <
669 _CheckArgsConstructor<
670 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31671 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25672 bool
673 >::type = false
674 >
Howard Hinnantee6ccd02010-09-23 18:58:28675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16676 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
677 : base_(allocator_arg_t(), __a,
678 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
679 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
680 typename __make_tuple_indices<0>::type(),
681 typename __make_tuple_types<tuple, 0>::type(),
682 __t...
683 ) {}
684
Eric Fiselier95526d32016-04-19 01:19:25685 template <class _Alloc, bool _Dummy = true,
686 typename enable_if
687 <
688 _CheckArgsConstructor<
689 _Dummy
Eric Fiselierfc044a12016-11-13 19:54:31690 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier95526d32016-04-19 01:19:25691 bool
692 >::type = false
693 >
694 _LIBCPP_INLINE_VISIBILITY
695 explicit
696 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
697 : base_(allocator_arg_t(), __a,
698 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
699 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
700 typename __make_tuple_indices<0>::type(),
701 typename __make_tuple_types<tuple, 0>::type(),
702 __t...
703 ) {}
704
Howard Hinnantbc8d3f92010-05-11 19:42:16705 template <class ..._Up,
Howard Hinnantdc1345f2012-04-01 23:10:42706 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16707 <
Eric Fiselierd5019332016-04-15 18:05:59708 _CheckArgsConstructor<
709 sizeof...(_Up) <= sizeof...(_Tp)
710 && !_PackExpandsToThisTuple<_Up...>::value
711 >::template __enable_implicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42712 bool
713 >::type = false
714 >
Marshall Clowda0a0e82013-07-22 16:02:19715 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42716 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48717 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21718 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48719 typename __make_tuple_indices<sizeof...(_Up)>::type,
720 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
721 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
722 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clow86d311c2014-09-16 17:08:21723 _Up...
Howard Hinnant74f26f22012-07-06 21:53:48724 >::value
725 ))
Howard Hinnantdc1345f2012-04-01 23:10:42726 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
727 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
728 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
729 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
730 _VSTD::forward<_Up>(__u)...) {}
731
732 template <class ..._Up,
733 typename enable_if
734 <
Eric Fiselierd5019332016-04-15 18:05:59735 _CheckArgsConstructor<
736 sizeof...(_Up) <= sizeof...(_Tp)
737 && !_PackExpandsToThisTuple<_Up...>::value
738 >::template __enable_explicit<_Up...>(),
Howard Hinnantdc1345f2012-04-01 23:10:42739 bool
Eric Fiselierd5019332016-04-15 18:05:59740 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16741 >
Marshall Clowda0a0e82013-07-22 16:02:19742 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16743 explicit
744 tuple(_Up&&... __u)
Howard Hinnant74f26f22012-07-06 21:53:48745 _NOEXCEPT_((
Marshall Clow86d311c2014-09-16 17:08:21746 is_nothrow_constructible<base,
Howard Hinnant74f26f22012-07-06 21:53:48747 typename __make_tuple_indices<sizeof...(_Up)>::type,
748 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
749 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
750 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
751 _Up...
752 >::value
753 ))
Howard Hinnantbc8d3f92010-05-11 19:42:16754 : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
755 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
756 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
757 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19758 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16759
760 template <class _Alloc, class ..._Up,
Eric Fiselier95526d32016-04-19 01:19:25761 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16762 <
Eric Fiselierd5019332016-04-15 18:05:59763 _CheckArgsConstructor<
764 sizeof...(_Up) == sizeof...(_Tp) &&
765 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier95526d32016-04-19 01:19:25766 >::template __enable_implicit<_Up...>(),
767 bool
768 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16769 >
Howard Hinnantee6ccd02010-09-23 18:58:28770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16771 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
772 : base_(allocator_arg_t(), __a,
773 typename __make_tuple_indices<sizeof...(_Up)>::type(),
774 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
775 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
776 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnant0949eed2011-06-30 21:18:19777 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16778
Eric Fiselier95526d32016-04-19 01:19:25779 template <class _Alloc, class ..._Up,
780 typename enable_if
781 <
782 _CheckArgsConstructor<
783 sizeof...(_Up) == sizeof...(_Tp) &&
784 !_PackExpandsToThisTuple<_Up...>::value
785 >::template __enable_explicit<_Up...>(),
786 bool
787 >::type = false
788 >
789 _LIBCPP_INLINE_VISIBILITY
790 explicit
791 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
792 : base_(allocator_arg_t(), __a,
793 typename __make_tuple_indices<sizeof...(_Up)>::type(),
794 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
795 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
796 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
797 _VSTD::forward<_Up>(__u)...) {}
798
Howard Hinnantbc8d3f92010-05-11 19:42:16799 template <class _Tuple,
Howard Hinnantdc1345f2012-04-01 23:10:42800 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16801 <
Eric Fiselierd5019332016-04-15 18:05:59802 _CheckTupleLikeConstructor<
803 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
804 && !_PackExpandsToThisTuple<_Tuple>::value
805 >::template __enable_implicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42806 bool
807 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16808 >
Marshall Clowda0a0e82013-07-22 16:02:19809 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant74f26f22012-07-06 21:53:48810 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnant0949eed2011-06-30 21:18:19811 : base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16812
Howard Hinnantdc1345f2012-04-01 23:10:42813 template <class _Tuple,
814 typename enable_if
815 <
Eric Fiselierd5019332016-04-15 18:05:59816 _CheckTupleLikeConstructor<
817 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
818 && !_PackExpandsToThisTuple<_Tuple>::value
819 >::template __enable_explicit<_Tuple>(),
Howard Hinnantdc1345f2012-04-01 23:10:42820 bool
821 >::type = false
822 >
Marshall Clowda0a0e82013-07-22 16:02:19823 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantdc1345f2012-04-01 23:10:42824 explicit
Howard Hinnant74f26f22012-07-06 21:53:48825 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
Howard Hinnantdc1345f2012-04-01 23:10:42826 : base_(_VSTD::forward<_Tuple>(__t)) {}
827
Howard Hinnantbc8d3f92010-05-11 19:42:16828 template <class _Alloc, class _Tuple,
Eric Fiselier95526d32016-04-19 01:19:25829 typename enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16830 <
Eric Fiselierd5019332016-04-15 18:05:59831 _CheckTupleLikeConstructor<
832 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
Eric Fiselier95526d32016-04-19 01:19:25833 >::template __enable_implicit<_Tuple>(),
834 bool
835 >::type = false
Howard Hinnantbc8d3f92010-05-11 19:42:16836 >
Howard Hinnantee6ccd02010-09-23 18:58:28837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16838 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Howard Hinnant0949eed2011-06-30 21:18:19839 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16840
Eric Fiselier95526d32016-04-19 01:19:25841 template <class _Alloc, class _Tuple,
842 typename enable_if
843 <
844 _CheckTupleLikeConstructor<
845 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
846 >::template __enable_explicit<_Tuple>(),
847 bool
848 >::type = false
849 >
850 _LIBCPP_INLINE_VISIBILITY
851 explicit
852 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
853 : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
854
Eric Fiselier4be71c62016-07-25 02:36:42855 using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
856 using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
857
858 _LIBCPP_INLINE_VISIBILITY
859 tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
860 _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
861 {
862 base_.operator=(__t.base_);
863 return *this;
864 }
865
866 _LIBCPP_INLINE_VISIBILITY
867 tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
868 _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
869 {
870 base_.operator=(static_cast<base&&>(__t.base_));
871 return *this;
872 }
873
Howard Hinnantbc8d3f92010-05-11 19:42:16874 template <class _Tuple,
875 class = typename enable_if
876 <
877 __tuple_assignable<_Tuple, tuple>::value
878 >::type
879 >
Howard Hinnantee6ccd02010-09-23 18:58:28880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16881 tuple&
Howard Hinnant74f26f22012-07-06 21:53:48882 operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16883 {
Howard Hinnant0949eed2011-06-30 21:18:19884 base_.operator=(_VSTD::forward<_Tuple>(__t));
Howard Hinnantbc8d3f92010-05-11 19:42:16885 return *this;
886 }
887
Howard Hinnantee6ccd02010-09-23 18:58:28888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18889 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
890 {base_.swap(__t.base_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16891};
892
893template <>
Howard Hinnant0f678bd2013-08-12 18:38:34894class _LIBCPP_TYPE_VIS_ONLY tuple<>
Howard Hinnantbc8d3f92010-05-11 19:42:16895{
896public:
Howard Hinnantee6ccd02010-09-23 18:58:28897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4eebfc32012-07-06 20:50:27898 _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16899 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48901 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16902 template <class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48904 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50905 template <class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48907 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnant99968442011-11-29 18:15:50908 template <class _Alloc, class _Up>
Howard Hinnantee6ccd02010-09-23 18:58:28909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f26f22012-07-06 21:53:48910 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantee6ccd02010-09-23 18:58:28911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta5e01212011-05-27 19:08:18912 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16913};
914
915template <class ..._Tp>
916inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32917typename enable_if
918<
919 __all<__is_swappable<_Tp>::value...>::value,
920 void
921>::type
Howard Hinnanta5e01212011-05-27 19:08:18922swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
923 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
924 {__t.swap(__u);}
Howard Hinnantbc8d3f92010-05-11 19:42:16925
926// get
927
928template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36929inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25930typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04931get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16932{
Howard Hinnantf83417b2011-01-24 16:07:25933 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16934 return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
935}
936
937template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36938inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25939const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnantec3773c2011-12-01 20:21:04940get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16941{
Howard Hinnantf83417b2011-01-24 16:07:25942 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16943 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
944}
945
Howard Hinnantcd2254b2010-11-17 19:52:17946template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36947inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25948typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnantec3773c2011-12-01 20:21:04949get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17950{
Howard Hinnantf83417b2011-01-24 16:07:25951 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnant56a85ca2011-01-25 16:31:30952 return static_cast<type&&>(
Douglas Gregor6c669942011-01-25 16:14:21953 static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
Howard Hinnantcd2254b2010-11-17 19:52:17954}
955
Eric Fiselier199bee02015-12-18 00:36:55956template <size_t _Ip, class ..._Tp>
957inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
958const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
959get(const tuple<_Tp...>&& __t) _NOEXCEPT
960{
961 typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
962 return static_cast<const type&&>(
963 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get());
964}
965
Marshall Clowe8029e52013-07-13 02:54:05966#if _LIBCPP_STD_VER > 11
Marshall Clowe8029e52013-07-13 02:54:05967
Eric Fiselier22c3e762016-07-02 03:18:30968namespace __find_detail {
Marshall Clowe8029e52013-07-13 02:54:05969
Eric Fiselier22c3e762016-07-02 03:18:30970static constexpr size_t __not_found = -1;
971static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clowe8029e52013-07-13 02:54:05972
Eric Fiselier22c3e762016-07-02 03:18:30973inline _LIBCPP_INLINE_VISIBILITY
974constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
975 return !__matches ? __res :
976 (__res == __not_found ? __curr_i : __ambiguous);
977}
Marshall Clowe8029e52013-07-13 02:54:05978
Eric Fiselier22c3e762016-07-02 03:18:30979template <size_t _Nx>
980inline _LIBCPP_INLINE_VISIBILITY
981constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
982 return __i == _Nx ? __not_found :
983 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
984}
985
986template <class _T1, class ..._Args>
987struct __find_exactly_one_checked {
988 static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
989 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
990 static_assert (value != __not_found, "type not found in type list" );
991 static_assert(value != __ambiguous,"type occurs more than once in type list");
992};
993
Eric Fiselier990090f2016-07-02 03:46:08994template <class _T1>
995struct __find_exactly_one_checked<_T1> {
996 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
997};
998
Eric Fiselier22c3e762016-07-02 03:18:30999} // namespace __find_detail;
Marshall Clowe8029e52013-07-13 02:54:051000
1001template <typename _T1, typename... _Args>
Eric Fiselier22c3e762016-07-02 03:18:301002struct __find_exactly_one_t
1003 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1004};
Marshall Clowe8029e52013-07-13 02:54:051005
1006template <class _T1, class... _Args>
1007inline _LIBCPP_INLINE_VISIBILITY
1008constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1009{
1010 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1011}
1012
1013template <class _T1, class... _Args>
1014inline _LIBCPP_INLINE_VISIBILITY
1015constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1016{
1017 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1018}
1019
1020template <class _T1, class... _Args>
1021inline _LIBCPP_INLINE_VISIBILITY
1022constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1023{
Marshall Clow01a0e902013-07-15 20:46:111024 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clowe8029e52013-07-13 02:54:051025}
1026
Eric Fiselier199bee02015-12-18 00:36:551027template <class _T1, class... _Args>
1028inline _LIBCPP_INLINE_VISIBILITY
1029constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1030{
1031 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1032}
1033
Marshall Clowe8029e52013-07-13 02:54:051034#endif
1035
Howard Hinnantbc8d3f92010-05-11 19:42:161036// tie
1037
1038template <class ..._Tp>
Marshall Clow8e554d92014-02-25 16:11:461039inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161040tuple<_Tp&...>
Howard Hinnant74f26f22012-07-06 21:53:481041tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161042{
1043 return tuple<_Tp&...>(__t...);
1044}
1045
1046template <class _Up>
1047struct __ignore_t
1048{
Howard Hinnantbc8d3f92010-05-11 19:42:161049 template <class _Tp>
Howard Hinnantee6ccd02010-09-23 18:58:281050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161051 const __ignore_t& operator=(_Tp&&) const {return *this;}
1052};
1053
1054namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
1055
Howard Hinnantbc8d3f92010-05-11 19:42:161056template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:491057struct __make_tuple_return_impl
Howard Hinnantbc8d3f92010-05-11 19:42:161058{
1059 typedef _Tp type;
1060};
1061
1062template <class _Tp>
Marshall Clowa71f9562014-01-03 22:55:491063struct __make_tuple_return_impl<reference_wrapper<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:161064{
1065 typedef _Tp& type;
1066};
1067
1068template <class _Tp>
1069struct __make_tuple_return
1070{
Marshall Clowa71f9562014-01-03 22:55:491071 typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:161072};
1073
1074template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:191075inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161076tuple<typename __make_tuple_return<_Tp>::type...>
1077make_tuple(_Tp&&... __t)
1078{
Howard Hinnant0949eed2011-06-30 21:18:191079 return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161080}
1081
Howard Hinnant3c1ffba2010-08-19 18:59:381082template <class... _Tp>
Marshall Clowda0a0e82013-07-22 16:02:191083inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1084tuple<_Tp&&...>
Howard Hinnant74f26f22012-07-06 21:53:481085forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3c1ffba2010-08-19 18:59:381086{
Howard Hinnant0949eed2011-06-30 21:18:191087 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3c1ffba2010-08-19 18:59:381088}
1089
Howard Hinnant99968442011-11-29 18:15:501090template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:161091struct __tuple_equal
1092{
1093 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:191094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161095 bool operator()(const _Tp& __x, const _Up& __y)
1096 {
Marshall Clowba6dbf42014-06-24 00:46:191097 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantbc8d3f92010-05-11 19:42:161098 }
1099};
1100
1101template <>
1102struct __tuple_equal<0>
1103{
1104 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:191105 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161106 bool operator()(const _Tp&, const _Up&)
1107 {
1108 return true;
1109 }
1110};
1111
1112template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:191113inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161114bool
1115operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1116{
1117 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1118}
1119
1120template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:191121inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161122bool
1123operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1124{
1125 return !(__x == __y);
1126}
1127
Howard Hinnant99968442011-11-29 18:15:501128template <size_t _Ip>
Howard Hinnantbc8d3f92010-05-11 19:42:161129struct __tuple_less
1130{
1131 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:191132 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161133 bool operator()(const _Tp& __x, const _Up& __y)
1134 {
Duncan P. N. Exon Smith07b133f2015-01-21 02:51:171135 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1136 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1137 return true;
1138 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1139 return false;
1140 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantbc8d3f92010-05-11 19:42:161141 }
1142};
1143
1144template <>
1145struct __tuple_less<0>
1146{
1147 template <class _Tp, class _Up>
Marshall Clowda0a0e82013-07-22 16:02:191148 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161149 bool operator()(const _Tp&, const _Up&)
1150 {
1151 return false;
1152 }
1153};
1154
1155template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:191156inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161157bool
1158operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1159{
1160 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1161}
1162
1163template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:191164inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161165bool
1166operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1167{
1168 return __y < __x;
1169}
1170
1171template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:191172inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161173bool
1174operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1175{
1176 return !(__x < __y);
1177}
1178
1179template <class ..._Tp, class ..._Up>
Marshall Clowda0a0e82013-07-22 16:02:191180inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:161181bool
1182operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1183{
1184 return !(__y < __x);
1185}
1186
1187// tuple_cat
1188
Howard Hinnant0e1493e2010-12-11 20:47:501189template <class _Tp, class _Up> struct __tuple_cat_type;
1190
1191template <class ..._Ttypes, class ..._Utypes>
Howard Hinnantf83417b2011-01-24 16:07:251192struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantbc8d3f92010-05-11 19:42:161193{
Howard Hinnant0e1493e2010-12-11 20:47:501194 typedef tuple<_Ttypes..., _Utypes...> type;
1195};
1196
1197template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1198struct __tuple_cat_return_1
1199{
1200};
1201
1202template <class ..._Types, class _Tuple0>
1203struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1204{
1205 typedef typename __tuple_cat_type<tuple<_Types...>,
1206 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type
1207 type;
1208};
1209
1210template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1211struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1212 : public __tuple_cat_return_1<
1213 typename __tuple_cat_type<
1214 tuple<_Types...>,
1215 typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type
1216 >::type,
1217 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1218 _Tuple1, _Tuples...>
1219{
1220};
1221
1222template <class ..._Tuples> struct __tuple_cat_return;
1223
1224template <class _Tuple0, class ..._Tuples>
1225struct __tuple_cat_return<_Tuple0, _Tuples...>
1226 : public __tuple_cat_return_1<tuple<>,
1227 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1228 _Tuples...>
1229{
1230};
1231
1232template <>
1233struct __tuple_cat_return<>
1234{
1235 typedef tuple<> type;
1236};
1237
Marshall Clowda0a0e82013-07-22 16:02:191238inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant0e1493e2010-12-11 20:47:501239tuple<>
1240tuple_cat()
1241{
1242 return tuple<>();
Howard Hinnantbc8d3f92010-05-11 19:42:161243}
1244
Howard Hinnant99968442011-11-29 18:15:501245template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnante48e3662010-12-12 23:04:371246struct __tuple_cat_return_ref_imp;
Howard Hinnantbc8d3f92010-05-11 19:42:161247
Howard Hinnante48e3662010-12-12 23:04:371248template <class ..._Types, size_t ..._I0, class _Tuple0>
1249struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantbc8d3f92010-05-11 19:42:161250{
Howard Hinnant0e1493e2010-12-11 20:47:501251 typedef typename remove_reference<_Tuple0>::type _T0;
Howard Hinnante48e3662010-12-12 23:04:371252 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1253 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1254};
Howard Hinnantbc8d3f92010-05-11 19:42:161255
Howard Hinnante48e3662010-12-12 23:04:371256template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1257struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1258 _Tuple0, _Tuple1, _Tuples...>
1259 : public __tuple_cat_return_ref_imp<
1260 tuple<_Types..., typename __apply_cv<_Tuple0,
1261 typename tuple_element<_I0,
1262 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1263 typename __make_tuple_indices<tuple_size<typename
1264 remove_reference<_Tuple1>::type>::value>::type,
1265 _Tuple1, _Tuples...>
Howard Hinnantbc8d3f92010-05-11 19:42:161266{
Howard Hinnante48e3662010-12-12 23:04:371267};
1268
1269template <class _Tuple0, class ..._Tuples>
1270struct __tuple_cat_return_ref
1271 : public __tuple_cat_return_ref_imp<tuple<>,
1272 typename __make_tuple_indices<
1273 tuple_size<typename remove_reference<_Tuple0>::type>::value
1274 >::type, _Tuple0, _Tuples...>
1275{
1276};
1277
1278template <class _Types, class _I0, class _J0>
1279struct __tuple_cat;
1280
1281template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnantf83417b2011-01-24 16:07:251282struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnante48e3662010-12-12 23:04:371283{
1284 template <class _Tuple0>
Marshall Clowda0a0e82013-07-22 16:02:191285 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:371286 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1287 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1288 {
Marshall Clowba6dbf42014-06-24 00:46:191289 return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1290 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnante48e3662010-12-12 23:04:371291 }
1292
1293 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clowda0a0e82013-07-22 16:02:191294 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:371295 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1296 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1297 {
1298 typedef typename remove_reference<_Tuple0>::type _T0;
1299 typedef typename remove_reference<_Tuple1>::type _T1;
1300 return __tuple_cat<
1301 tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
1302 typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
1303 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
Marshall Clow1d927e32013-10-05 18:46:371304 (forward_as_tuple(
Marshall Clowba6dbf42014-06-24 00:46:191305 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1306 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
Howard Hinnante48e3662010-12-12 23:04:371307 ),
Howard Hinnant0949eed2011-06-30 21:18:191308 _VSTD::forward<_Tuple1>(__t1),
1309 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnante48e3662010-12-12 23:04:371310 }
1311};
1312
1313template <class _Tuple0, class... _Tuples>
Marshall Clowda0a0e82013-07-22 16:02:191314inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnante48e3662010-12-12 23:04:371315typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1316tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1317{
1318 typedef typename remove_reference<_Tuple0>::type _T0;
1319 return __tuple_cat<tuple<>, __tuple_indices<>,
1320 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnant0949eed2011-06-30 21:18:191321 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1322 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161323}
1324
1325template <class ..._Tp, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:341326struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:161327 : true_type {};
1328
Eric Fiseliere1445fd2016-07-25 04:32:071329#endif // _LIBCPP_HAS_NO_VARIADICS
1330
1331#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:161332template <class _T1, class _T2>
1333template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
1334inline _LIBCPP_INLINE_VISIBILITY
1335pair<_T1, _T2>::pair(piecewise_construct_t,
1336 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1337 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:191338 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1339 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantbc8d3f92010-05-11 19:42:161340{
1341}
Eric Fiseliere1445fd2016-07-25 04:32:071342#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:161343
Eric Fiselier5839fed2016-07-18 00:35:561344#if _LIBCPP_STD_VER > 14
1345template <class _Tp>
1346constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
1347
1348#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1349
1350template <class _Fn, class _Tuple, size_t ..._Id>
1351inline _LIBCPP_INLINE_VISIBILITY
1352constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1353 __tuple_indices<_Id...>)
1354_LIBCPP_NOEXCEPT_RETURN(
1355 _VSTD::__invoke_constexpr(
1356 _VSTD::forward<_Fn>(__f),
1357 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1358)
1359
1360template <class _Fn, class _Tuple>
1361inline _LIBCPP_INLINE_VISIBILITY
1362constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1363_LIBCPP_NOEXCEPT_RETURN(
1364 _VSTD::__apply_tuple_impl(
1365 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
1366 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1367)
1368
1369template <class _Tp, class _Tuple, size_t... _Idx>
1370inline _LIBCPP_INLINE_VISIBILITY
1371constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1372_LIBCPP_NOEXCEPT_RETURN(
1373 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1374)
1375
1376template <class _Tp, class _Tuple>
1377inline _LIBCPP_INLINE_VISIBILITY
1378constexpr _Tp make_from_tuple(_Tuple&& __t)
1379_LIBCPP_NOEXCEPT_RETURN(
1380 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
1381 typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{})
1382)
1383
1384#undef _LIBCPP_NOEXCEPT_RETURN
1385
1386#endif // _LIBCPP_STD_VER > 14
1387
Howard Hinnantbc8d3f92010-05-11 19:42:161388_LIBCPP_END_NAMESPACE_STD
1389
1390#endif // _LIBCPP_TUPLE