blob: 61ff2125623f79527371f75e150effbec54865ed [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- tuple ------------------------------------===//
3//
Chandler Carruth7642bb12019-01-19 08:50:56 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TUPLE
11#define _LIBCPP_TUPLE
12
13/*
14 tuple synopsis
15
16namespace std
17{
18
19template <class... T>
20class tuple {
21public:
Louis Dionnea7a2beb2019-09-26 14:51:10 +000022 explicit(see-below) constexpr tuple();
Louis Dionne1afad1d2019-07-22 20:45:23 +000023 explicit(see-below) tuple(const T&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000024 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000025 explicit(see-below) tuple(U&&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000026 tuple(const tuple&) = default;
Howard Hinnant89ef1212011-05-27 19:08:18 +000027 tuple(tuple&&) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +000028 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000029 explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000030 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000031 explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000033 explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000034 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000035 explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000036
37 // allocator-extended constructors
38 template <class Alloc>
39 tuple(allocator_arg_t, const Alloc& a);
40 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050041 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050043 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000044 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050045 tuple(allocator_arg_t, const Alloc& a, const tuple&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000046 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050047 tuple(allocator_arg_t, const Alloc& a, tuple&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000048 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050049 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000050 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050051 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000052 template <class Alloc, class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050053 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000054 template <class Alloc, class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050055 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050057 tuple& operator=(const tuple&); // constexpr in C++20
58 tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000059 template <class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050060 tuple& operator=(const tuple<U...>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000061 template <class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050062 tuple& operator=(tuple<U...>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000063 template <class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050064 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000065 template <class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050066 tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000067
Louis Dionne6c0d5342018-07-31 11:56:20 -040068 template<class U, size_t N>
69 tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
70 template<class U, size_t N>
71 tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
72
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050073 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000074};
75
Louis Dionne616da2a2019-08-12 18:30:31 +000076template <class ...T>
77tuple(T...) -> tuple<T...>; // since C++17
78template <class T1, class T2>
79tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
80template <class Alloc, class ...T>
81tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
82template <class Alloc, class T1, class T2>
83tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
84template <class Alloc, class ...T>
85tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
86
Marshall Clowf1bf62f2018-01-02 17:17:01 +000087inline constexpr unspecified ignore;
Howard Hinnantc51e1022010-05-11 19:42:16 +000088
Marshall Clow2229cee2013-07-22 16:02:19 +000089template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clowded420b2013-10-05 18:46:37 +000090template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clowa8892812014-02-25 16:11:46 +000091template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clow2229cee2013-07-22 16:02:19 +000092template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier8e892c52016-07-18 00:35:56 +000093
94// [tuple.apply], calling a function with a tuple of arguments:
95template <class F, class Tuple>
96 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
97template <class T, class Tuple>
98 constexpr T make_from_tuple(Tuple&& t); // C++17
99
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100// 20.4.1.4, tuple helper classes:
Marshall Clowce62b4d2019-01-11 21:57:12 +0000101template <class T> struct tuple_size; // undefined
102template <class... T> struct tuple_size<tuple<T...>>;
Eric Fiselier8e892c52016-07-18 00:35:56 +0000103template <class T>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000104 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Louis Dionnee684aa62019-04-01 16:39:34 +0000105template <size_t I, class T> struct tuple_element; // undefined
106template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
Marshall Clow36907512015-11-19 19:45:29 +0000107template <size_t I, class T>
108 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000109
110// 20.4.1.5, element access:
Marshall Clow36907512015-11-19 19:45:29 +0000111template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000112 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000113 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000114template <size_t I, class... T>
115 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000116 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000117template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000118 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow0abb1042013-07-17 18:25:36 +0000119 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000120template <size_t I, class... T>
121 const typename tuple_element<I, tuple<T...>>::type&&
122 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123
Marshall Clow15b02e02013-07-13 02:54:05 +0000124template <class T1, class... T>
125 constexpr T1& get(tuple<T...>&) noexcept; // C++14
126template <class T1, class... T>
Marshall Clow36907512015-11-19 19:45:29 +0000127 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000128template <class T1, class... T>
129 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000130template <class T1, class... T>
131 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000132
Howard Hinnantc51e1022010-05-11 19:42:16 +0000133// 20.4.1.6, relational operators:
Marshall Clow2229cee2013-07-22 16:02:19 +0000134template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
135template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
136template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
137template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
138template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
139template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140
141template <class... Types, class Alloc>
142 struct uses_allocator<tuple<Types...>, Alloc>;
143
144template <class... Types>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000145 void
146 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148} // std
149
150*/
151
152#include <__config>
153#include <__tuple>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400154#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000157#include <__functional_base>
158#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000159#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000161#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000162#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000163#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164
165_LIBCPP_BEGIN_NAMESPACE_STD
166
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000167#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000168
Marshall Clowf50d66f2014-03-03 06:18:11 +0000169
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170// __tuple_leaf
171
Eric Fiselierf7394302015-06-13 07:08:02 +0000172template <size_t _Ip, class _Hp,
173 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000174 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175class __tuple_leaf;
176
177template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500178inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000180 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181{
182 swap(__x.get(), __y.get());
183}
184
185template <size_t _Ip, class _Hp, bool>
186class __tuple_leaf
187{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000188 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189
Eric Fiselierca8bba12016-07-20 02:57:39 +0000190 template <class _Tp>
191 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000192#if __has_keyword(__reference_binds_to_temporary)
193 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000194#else
195 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000196#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000197 }
198
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500199 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200 __tuple_leaf& operator=(const __tuple_leaf&);
201public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500202 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000203 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000204 {static_assert(!is_reference<_Hp>::value,
205 "Attempted to default construct a reference element in a tuple");}
206
207 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500208 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000209 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000210 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000211 {static_assert(!is_reference<_Hp>::value,
212 "Attempted to default construct a reference element in a tuple");}
213
214 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500215 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000217 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218 {static_assert(!is_reference<_Hp>::value,
219 "Attempted to default construct a reference element in a tuple");}
220
221 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500222 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000223 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000224 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000225 {static_assert(!is_reference<_Hp>::value,
226 "Attempted to default construct a reference element in a tuple");}
227
Howard Hinnant693fc212010-09-27 17:54:17 +0000228 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000229 class = _EnableIf<
230 _And<
231 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
232 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000233 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000234 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000235 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000236 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000237 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000238 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000239 {static_assert(__can_bind_reference<_Tp&&>(),
240 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000241
242 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500243 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000244 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000245 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000246 {static_assert(__can_bind_reference<_Tp&&>(),
247 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000248
249 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500250 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000252 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000253 {static_assert(!is_reference<_Hp>::value,
254 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255
256 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500257 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000258 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000259 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000260 {static_assert(!is_reference<_Hp>::value,
261 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262
Marshall Clow47fcee52014-04-21 23:48:09 +0000263 __tuple_leaf(const __tuple_leaf& __t) = default;
264 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000265
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500266 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000267 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000269 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 return 0;
271 }
272
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000273 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
274 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275};
276
277template <size_t _Ip, class _Hp>
278class __tuple_leaf<_Ip, _Hp, true>
279 : private _Hp
280{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500281 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 __tuple_leaf& operator=(const __tuple_leaf&);
283public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500284 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000285 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286
287 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500288 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
290
291 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500292 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
294 : _Hp(allocator_arg_t(), __a) {}
295
296 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500297 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000298 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
299 : _Hp(__a) {}
300
Howard Hinnant693fc212010-09-27 17:54:17 +0000301 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000302 class = _EnableIf<
303 _And<
304 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
305 is_constructible<_Hp, _Tp>
306 >::value
307 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000308 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000309 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000310 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000311 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312
313 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500314 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000316 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317
318 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500319 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000321 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000322
323 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500324 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000326 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000328 __tuple_leaf(__tuple_leaf const &) = default;
329 __tuple_leaf(__tuple_leaf &&) = default;
330
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500331 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000332 int
333 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000334 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000335 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336 return 0;
337 }
338
Marshall Clow2229cee2013-07-22 16:02:19 +0000339 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
340 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341};
342
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000343template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500344_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000345void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346
Marshall Clowc470eae2014-10-15 10:33:02 +0000347template <class _Tp>
348struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000349
Marshall Clowc470eae2014-10-15 10:33:02 +0000350template <class ..._Tp>
351struct __all_default_constructible<__tuple_types<_Tp...>>
352 : __all<is_default_constructible<_Tp>::value...>
353{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000354
Howard Hinnantc51e1022010-05-11 19:42:16 +0000355// __tuple_impl
356
357template<class _Indx, class ..._Tp> struct __tuple_impl;
358
359template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000360struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000361 : public __tuple_leaf<_Indx, _Tp>...
362{
Howard Hinnant38469632012-07-06 20:39:45 +0000363 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500364 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000365 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000366
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367 template <size_t ..._Uf, class ..._Tf,
368 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000369 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370 explicit
371 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
372 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000373 _Up&&... __u)
374 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
375 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000376 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377 __tuple_leaf<_Ul, _Tl>()...
378 {}
379
380 template <class _Alloc, size_t ..._Uf, class ..._Tf,
381 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500382 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383 explicit
384 __tuple_impl(allocator_arg_t, const _Alloc& __a,
385 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
386 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
387 _Up&&... __u) :
388 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000389 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
391 {}
392
393 template <class _Tuple,
394 class = typename enable_if
395 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000396 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397 >::type
398 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000399 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000400 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
401 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000402 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
403 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404 {}
405
406 template <class _Alloc, class _Tuple,
407 class = typename enable_if
408 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000409 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410 >::type
411 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500412 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
414 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000415 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000416 _VSTD::forward<typename tuple_element<_Indx,
417 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000418 {}
419
Howard Hinnant0d032d12013-11-06 17:45:43 +0000420 __tuple_impl(const __tuple_impl&) = default;
421 __tuple_impl(__tuple_impl&&) = default;
422
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500423 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000425 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400427 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 }
429};
430
Louis Dionne6c0d5342018-07-31 11:56:20 -0400431template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500432_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400433void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
434 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
435}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000436
Louis Dionne6c0d5342018-07-31 11:56:20 -0400437template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500438_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400439void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
440 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500441 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400442 ), void(), 0)...);
443}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000444
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000446class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000448 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000450 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451
Eric Fiselier41b686e2016-12-08 23:57:08 +0000452#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
453 static constexpr bool _EnableImplicitReducedArityExtension = true;
454#else
455 static constexpr bool _EnableImplicitReducedArityExtension = false;
456#endif
457
Eric Fiselier264d04a2016-04-15 18:05:59 +0000458 template <class ..._Args>
459 struct _PackExpandsToThisTuple : false_type {};
460
461 template <class _Arg>
462 struct _PackExpandsToThisTuple<_Arg>
463 : is_same<typename __uncvref<_Arg>::type, tuple> {};
464
465 template <bool _MaybeEnable, class _Dummy = void>
466 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
467
468 template <class _Dummy>
469 struct _CheckArgsConstructor<true, _Dummy>
470 {
Eric Fiselier18d72a02019-09-30 20:55:30 +0000471 template <int&...>
472 static constexpr bool __enable_implicit_default() {
473 return __all<__is_implicitly_default_constructible<_Tp>::value... >::value;
474 }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000475
Eric Fiselier18d72a02019-09-30 20:55:30 +0000476 template <int&...>
477 static constexpr bool __enable_explicit_default() {
478 return
479 __all<is_default_constructible<_Tp>::value...>::value &&
480 !__enable_implicit_default< >();
481 }
482
Eric Fiseliere61db632016-07-25 04:32:07 +0000483
484 template <class ..._Args>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000485 static constexpr bool __enable_explicit() {
486 return
487 __tuple_constructible<
488 tuple<_Args...>,
489 typename __make_tuple_types<tuple,
490 sizeof...(_Args) < sizeof...(_Tp) ?
491 sizeof...(_Args) :
492 sizeof...(_Tp)>::type
493 >::value &&
494 !__tuple_convertible<
495 tuple<_Args...>,
496 typename __make_tuple_types<tuple,
497 sizeof...(_Args) < sizeof...(_Tp) ?
498 sizeof...(_Args) :
499 sizeof...(_Tp)>::type
500 >::value &&
501 __all_default_constructible<
502 typename __make_tuple_types<tuple, sizeof...(_Tp),
503 sizeof...(_Args) < sizeof...(_Tp) ?
504 sizeof...(_Args) :
505 sizeof...(_Tp)>::type
506 >::value;
507 }
508
509 template <class ..._Args>
510 static constexpr bool __enable_implicit() {
511 return
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000512 __tuple_constructible<
513 tuple<_Args...>,
514 typename __make_tuple_types<tuple,
515 sizeof...(_Args) < sizeof...(_Tp) ?
516 sizeof...(_Args) :
517 sizeof...(_Tp)>::type
518 >::value &&
Eric Fiselier264d04a2016-04-15 18:05:59 +0000519 __tuple_convertible<
520 tuple<_Args...>,
521 typename __make_tuple_types<tuple,
522 sizeof...(_Args) < sizeof...(_Tp) ?
523 sizeof...(_Args) :
524 sizeof...(_Tp)>::type
525 >::value &&
526 __all_default_constructible<
527 typename __make_tuple_types<tuple, sizeof...(_Tp),
528 sizeof...(_Args) < sizeof...(_Tp) ?
529 sizeof...(_Args) :
530 sizeof...(_Tp)>::type
531 >::value;
532 }
533 };
534
535 template <bool _MaybeEnable,
536 bool = sizeof...(_Tp) == 1,
537 class _Dummy = void>
538 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
539
540 template <class _Dummy>
541 struct _CheckTupleLikeConstructor<true, false, _Dummy>
542 {
543 template <class _Tuple>
544 static constexpr bool __enable_implicit() {
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000545 return __tuple_constructible<_Tuple, tuple>::value
546 && __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000547 }
548
549 template <class _Tuple>
550 static constexpr bool __enable_explicit() {
Eric Fiselierb3225562016-12-15 06:34:54 +0000551 return __tuple_constructible<_Tuple, tuple>::value
552 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000553 }
554 };
555
556 template <class _Dummy>
557 struct _CheckTupleLikeConstructor<true, true, _Dummy>
558 {
559 // This trait is used to disable the tuple-like constructor when
560 // the UTypes... constructor should be selected instead.
561 // See LWG issue #2549.
562 template <class _Tuple>
Eric Fiselier3906a132019-06-23 20:28:29 +0000563 using _PreferTupleLikeConstructor = _Or<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000564 // Don't attempt the two checks below if the tuple we are given
565 // has the same type as this tuple.
Eric Fiselier3906a132019-06-23 20:28:29 +0000566 _IsSame<__uncvref_t<_Tuple>, tuple>,
567 _Lazy<_And,
568 _Not<is_constructible<_Tp..., _Tuple>>,
569 _Not<is_convertible<_Tuple, _Tp...>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000570 >
571 >;
572
573 template <class _Tuple>
574 static constexpr bool __enable_implicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000575 return _And<
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000576 __tuple_constructible<_Tuple, tuple>,
Eric Fiselier264d04a2016-04-15 18:05:59 +0000577 __tuple_convertible<_Tuple, tuple>,
578 _PreferTupleLikeConstructor<_Tuple>
579 >::value;
580 }
581
582 template <class _Tuple>
583 static constexpr bool __enable_explicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000584 return _And<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000585 __tuple_constructible<_Tuple, tuple>,
586 _PreferTupleLikeConstructor<_Tuple>,
Eric Fiselier3906a132019-06-23 20:28:29 +0000587 _Not<__tuple_convertible<_Tuple, tuple>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000588 >::value;
589 }
590 };
591
Eric Fiselierec5a2102019-07-12 23:01:48 +0000592 template <class _Tuple, bool _DisableIfLValue>
593 using _EnableImplicitTupleLikeConstructor = _EnableIf<
594 _CheckTupleLikeConstructor<
595 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
596 && !_PackExpandsToThisTuple<_Tuple>::value
597 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
598 >::template __enable_implicit<_Tuple>(),
599 bool
600 >;
601
602 template <class _Tuple, bool _DisableIfLValue>
603 using _EnableExplicitTupleLikeConstructor = _EnableIf<
604 _CheckTupleLikeConstructor<
605 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
606 && !_PackExpandsToThisTuple<_Tuple>::value
607 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
608 >::template __enable_explicit<_Tuple>(),
609 bool
610 >;
Marshall Clow0abb1042013-07-17 18:25:36 +0000611 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000612 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000613 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000614 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000615 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000616 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000617 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
618 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000619public:
620
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000621 template <bool _Dummy = true, _EnableIf<
Eric Fiselier18d72a02019-09-30 20:55:30 +0000622 _CheckArgsConstructor<_Dummy>::__enable_implicit_default()
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000623 , void*> = nullptr>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500624 _LIBCPP_INLINE_VISIBILITY constexpr
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000625 tuple()
626 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
627
628 template <bool _Dummy = true, _EnableIf<
Eric Fiselier18d72a02019-09-30 20:55:30 +0000629 _CheckArgsConstructor<_Dummy>::__enable_explicit_default()
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000630 , void*> = nullptr>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500631 explicit _LIBCPP_INLINE_VISIBILITY constexpr
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000632 tuple()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000633 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000634
Eric Fiselier737a16d2016-07-25 02:36:42 +0000635 tuple(tuple const&) = default;
636 tuple(tuple&&) = default;
637
Eric Fiselier18d72a02019-09-30 20:55:30 +0000638 template <class _AllocArgT, class _Alloc, _EnableIf<
639 _CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value >::__enable_implicit_default()
Louis Dionne668a50c2019-09-27 15:06:52 +0000640 , void*> = nullptr
Eric Fiselier3906a132019-06-23 20:28:29 +0000641 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500642 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselierc170df52016-04-15 03:29:40 +0000643 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000644 : __base_(allocator_arg_t(), __a,
Eric Fiselierc170df52016-04-15 03:29:40 +0000645 __tuple_indices<>(), __tuple_types<>(),
646 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
647 __tuple_types<_Tp...>()) {}
648
Eric Fiselier18d72a02019-09-30 20:55:30 +0000649 template <class _AllocArgT, class _Alloc, _EnableIf<
650 _CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value>::__enable_explicit_default()
Louis Dionne668a50c2019-09-27 15:06:52 +0000651 , void*> = nullptr
652 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500653 explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne668a50c2019-09-27 15:06:52 +0000654 tuple(_AllocArgT, _Alloc const& __a)
655 : __base_(allocator_arg_t(), __a,
656 __tuple_indices<>(), __tuple_types<>(),
657 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
658 __tuple_types<_Tp...>()) {}
659
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000660 template <bool _Dummy = true,
661 typename enable_if
662 <
663 _CheckArgsConstructor<
664 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000665 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000666 bool
667 >::type = false
668 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000669 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000670 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000671 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
673 typename __make_tuple_indices<0>::type(),
674 typename __make_tuple_types<tuple, 0>::type(),
675 __t...
676 ) {}
677
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000678 template <bool _Dummy = true,
679 typename enable_if
680 <
681 _CheckArgsConstructor<
682 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000683 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000684 bool
685 >::type = false
686 >
687 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
688 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000689 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000690 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
691 typename __make_tuple_indices<0>::type(),
692 typename __make_tuple_types<tuple, 0>::type(),
693 __t...
694 ) {}
695
696 template <class _Alloc, bool _Dummy = true,
697 typename enable_if
698 <
699 _CheckArgsConstructor<
700 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000701 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000702 bool
703 >::type = false
704 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500705 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000707 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000708 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
709 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
710 typename __make_tuple_indices<0>::type(),
711 typename __make_tuple_types<tuple, 0>::type(),
712 __t...
713 ) {}
714
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000715 template <class _Alloc, bool _Dummy = true,
716 typename enable_if
717 <
718 _CheckArgsConstructor<
719 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000720 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000721 bool
722 >::type = false
723 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500724 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000725 explicit
726 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000727 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000728 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
729 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
730 typename __make_tuple_indices<0>::type(),
731 typename __make_tuple_types<tuple, 0>::type(),
732 __t...
733 ) {}
734
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735 template <class ..._Up,
Eric Fiselier41b686e2016-12-08 23:57:08 +0000736 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnant65704d02012-04-01 23:10:42 +0000737 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000738 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000739 _CheckArgsConstructor<
Eric Fiselier41b686e2016-12-08 23:57:08 +0000740 sizeof...(_Up) == sizeof...(_Tp)
741 && !_PackIsTuple
742 >::template __enable_implicit<_Up...>() ||
743 _CheckArgsConstructor<
744 _EnableImplicitReducedArityExtension
745 && sizeof...(_Up) < sizeof...(_Tp)
746 && !_PackIsTuple
Eric Fiselier264d04a2016-04-15 18:05:59 +0000747 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000748 bool
749 >::type = false
750 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000751 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000752 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000753 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000754 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000755 typename __make_tuple_indices<sizeof...(_Up)>::type,
756 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
757 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
758 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clowcad20652014-09-16 17:08:21 +0000759 _Up...
Howard Hinnant62751642012-07-06 21:53:48 +0000760 >::value
761 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000762 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000763 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
764 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
765 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
766 _VSTD::forward<_Up>(__u)...) {}
767
768 template <class ..._Up,
769 typename enable_if
770 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000771 _CheckArgsConstructor<
772 sizeof...(_Up) <= sizeof...(_Tp)
773 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000774 >::template __enable_explicit<_Up...>() ||
775 _CheckArgsConstructor<
776 !_EnableImplicitReducedArityExtension
777 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselieredbbd402017-02-04 22:57:01 +0000778 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000779 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000780 bool
Eric Fiselier264d04a2016-04-15 18:05:59 +0000781 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000783 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784 explicit
785 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000786 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000787 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000788 typename __make_tuple_indices<sizeof...(_Up)>::type,
789 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
790 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
791 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
792 _Up...
793 >::value
794 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000795 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
797 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
798 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000799 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800
801 template <class _Alloc, class ..._Up,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000802 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000804 _CheckArgsConstructor<
805 sizeof...(_Up) == sizeof...(_Tp) &&
806 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000807 >::template __enable_implicit<_Up...>(),
808 bool
809 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500811 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000813 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814 typename __make_tuple_indices<sizeof...(_Up)>::type(),
815 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
816 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
817 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000818 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000820 template <class _Alloc, class ..._Up,
821 typename enable_if
822 <
823 _CheckArgsConstructor<
824 sizeof...(_Up) == sizeof...(_Tp) &&
825 !_PackExpandsToThisTuple<_Up...>::value
826 >::template __enable_explicit<_Up...>(),
827 bool
828 >::type = false
829 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500830 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000831 explicit
832 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000833 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000834 typename __make_tuple_indices<sizeof...(_Up)>::type(),
835 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
836 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
837 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
838 _VSTD::forward<_Up>(__u)...) {}
839
Eric Fiselierec5a2102019-07-12 23:01:48 +0000840 template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000841 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000842 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
843 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844
Eric Fiselierec5a2102019-07-12 23:01:48 +0000845 template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false>
846 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
847 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
848 : __base_(__t) {}
849 template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000850 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000851 explicit
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000852 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
853 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnant65704d02012-04-01 23:10:42 +0000854
Eric Fiselierec5a2102019-07-12 23:01:48 +0000855 template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false>
856 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
857 explicit
858 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
859 : __base_(__t) {}
860
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861 template <class _Alloc, class _Tuple,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000862 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000864 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000865 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
866 >::template __enable_implicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000867 bool
868 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500870 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000872 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000874 template <class _Alloc, class _Tuple,
875 typename enable_if
876 <
877 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000878 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
879 >::template __enable_explicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000880 bool
881 >::type = false
882 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500883 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000884 explicit
885 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000886 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000887
Louis Dionne6c0d5342018-07-31 11:56:20 -0400888 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500889 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400890 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
891 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000892 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400893 _VSTD::__memberwise_copy_assign(*this, __tuple,
894 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000895 return *this;
896 }
897
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500898 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400899 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
900 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000901 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400902 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
903 __tuple_types<_Tp...>(),
904 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000905 return *this;
906 }
907
Louis Dionne6c0d5342018-07-31 11:56:20 -0400908 template<class... _Up, _EnableIf<
909 _And<
910 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
911 is_assignable<_Tp&, _Up const&>...
912 >::value
913 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500914 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400915 tuple& operator=(tuple<_Up...> const& __tuple)
916 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
917 {
918 _VSTD::__memberwise_copy_assign(*this, __tuple,
919 typename __make_tuple_indices<sizeof...(_Tp)>::type());
920 return *this;
921 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000922
Louis Dionne6c0d5342018-07-31 11:56:20 -0400923 template<class... _Up, _EnableIf<
924 _And<
925 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
926 is_assignable<_Tp&, _Up>...
927 >::value
928 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500929 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400930 tuple& operator=(tuple<_Up...>&& __tuple)
931 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
932 {
933 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
934 __tuple_types<_Up...>(),
935 typename __make_tuple_indices<sizeof...(_Tp)>::type());
936 return *this;
937 }
938
939 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
940 _And<_Dep,
941 _BoolConstant<sizeof...(_Tp) == 2>,
942 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
943 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
944 >::value
945 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500946 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400947 tuple& operator=(pair<_Up1, _Up2> const& __pair)
948 _NOEXCEPT_((_And<
949 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
950 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
951 >::value))
952 {
953 _VSTD::get<0>(*this) = __pair.first;
954 _VSTD::get<1>(*this) = __pair.second;
955 return *this;
956 }
957
958 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
959 _And<_Dep,
960 _BoolConstant<sizeof...(_Tp) == 2>,
961 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
962 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
963 >::value
964 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500965 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400966 tuple& operator=(pair<_Up1, _Up2>&& __pair)
967 _NOEXCEPT_((_And<
968 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
969 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
970 >::value))
971 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500972 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
973 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -0400974 return *this;
975 }
976
977 // EXTENSION
978 template<class _Up, size_t _Np, class = _EnableIf<
979 _And<
980 _BoolConstant<_Np == sizeof...(_Tp)>,
981 is_assignable<_Tp&, _Up const&>...
982 >::value
983 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500984 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400985 tuple& operator=(array<_Up, _Np> const& __array)
986 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
987 {
988 _VSTD::__memberwise_copy_assign(*this, __array,
989 typename __make_tuple_indices<sizeof...(_Tp)>::type());
990 return *this;
991 }
992
993 // EXTENSION
994 template<class _Up, size_t _Np, class = void, class = _EnableIf<
995 _And<
996 _BoolConstant<_Np == sizeof...(_Tp)>,
997 is_assignable<_Tp&, _Up>...
998 >::value
999 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001000 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001001 tuple& operator=(array<_Up, _Np>&& __array)
1002 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1003 {
1004 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1005 __tuple_types<_If<true, _Up, _Tp>...>(),
1006 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1007 return *this;
1008 }
1009
1010 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001011 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001012 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001013 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014};
1015
1016template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001017class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001018{
1019public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001020 _LIBCPP_INLINE_VISIBILITY constexpr
1021 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001023 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001024 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001026 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001027 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001028 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001029 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001030 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001031 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001032 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001033 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001034 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001035 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036};
1037
Eric Fiselier8df4ac62017-10-04 00:04:26 +00001038#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Louis Dionne616da2a2019-08-12 18:30:31 +00001039template <class ..._Tp>
1040tuple(_Tp...) -> tuple<_Tp...>;
1041template <class _Tp1, class _Tp2>
1042tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1043template <class _Alloc, class ..._Tp>
1044tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1045template <class _Alloc, class _Tp1, class _Tp2>
1046tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1047template <class _Alloc, class ..._Tp>
1048tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001049#endif
1050
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001052inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001053typename enable_if
1054<
1055 __all<__is_swappable<_Tp>::value...>::value,
1056 void
1057>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001058swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1059 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1060 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061
1062// get
1063
1064template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001065inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001066typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001067get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001069 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001070 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001071}
1072
1073template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001074inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001075const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001076get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001078 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001079 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080}
1081
Howard Hinnant22e97242010-11-17 19:52:17 +00001082template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001083inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001084typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001085get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001086{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001087 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001088 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001089 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001090}
1091
Eric Fiselier6dea8092015-12-18 00:36:55 +00001092template <size_t _Ip, class ..._Tp>
1093inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1094const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1095get(const tuple<_Tp...>&& __t) _NOEXCEPT
1096{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001097 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001098 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001099 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001100}
1101
Marshall Clow15b02e02013-07-13 02:54:05 +00001102#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001103
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001104namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001105
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001106static constexpr size_t __not_found = -1;
1107static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001108
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001109inline _LIBCPP_INLINE_VISIBILITY
1110constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1111 return !__matches ? __res :
1112 (__res == __not_found ? __curr_i : __ambiguous);
1113}
Marshall Clow15b02e02013-07-13 02:54:05 +00001114
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001115template <size_t _Nx>
1116inline _LIBCPP_INLINE_VISIBILITY
1117constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1118 return __i == _Nx ? __not_found :
1119 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1120}
1121
1122template <class _T1, class ..._Args>
1123struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001124 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001125 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001126 static_assert(value != __not_found, "type not found in type list" );
1127 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001128};
1129
Eric Fiselier8087d302016-07-02 03:46:08 +00001130template <class _T1>
1131struct __find_exactly_one_checked<_T1> {
1132 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1133};
1134
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001135} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001136
1137template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001138struct __find_exactly_one_t
1139 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1140};
Marshall Clow15b02e02013-07-13 02:54:05 +00001141
1142template <class _T1, class... _Args>
1143inline _LIBCPP_INLINE_VISIBILITY
1144constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1145{
1146 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1147}
1148
1149template <class _T1, class... _Args>
1150inline _LIBCPP_INLINE_VISIBILITY
1151constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1152{
1153 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1154}
1155
1156template <class _T1, class... _Args>
1157inline _LIBCPP_INLINE_VISIBILITY
1158constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1159{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001160 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001161}
1162
Eric Fiselier6dea8092015-12-18 00:36:55 +00001163template <class _T1, class... _Args>
1164inline _LIBCPP_INLINE_VISIBILITY
1165constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1166{
1167 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1168}
1169
Marshall Clow15b02e02013-07-13 02:54:05 +00001170#endif
1171
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172// tie
1173
1174template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001175inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001177tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178{
1179 return tuple<_Tp&...>(__t...);
1180}
1181
1182template <class _Up>
1183struct __ignore_t
1184{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001185 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001186 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1187 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188};
1189
Eric Fiselier24e70262017-02-06 01:25:31 +00001190namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001191 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001192}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001193
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001195inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001196tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001197make_tuple(_Tp&&... __t)
1198{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001199 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200}
1201
Howard Hinnant3d203a32010-08-19 18:59:38 +00001202template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001203inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1204tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001205forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001206{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001207 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001208}
1209
Howard Hinnantc834c512011-11-29 18:15:50 +00001210template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001211struct __tuple_equal
1212{
1213 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001214 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215 bool operator()(const _Tp& __x, const _Up& __y)
1216 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001217 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001218 }
1219};
1220
1221template <>
1222struct __tuple_equal<0>
1223{
1224 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001225 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001226 bool operator()(const _Tp&, const _Up&)
1227 {
1228 return true;
1229 }
1230};
1231
1232template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001233inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234bool
1235operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1236{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001237 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1239}
1240
1241template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001242inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001243bool
1244operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1245{
1246 return !(__x == __y);
1247}
1248
Howard Hinnantc834c512011-11-29 18:15:50 +00001249template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001250struct __tuple_less
1251{
1252 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001253 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254 bool operator()(const _Tp& __x, const _Up& __y)
1255 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001256 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1257 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1258 return true;
1259 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1260 return false;
1261 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262 }
1263};
1264
1265template <>
1266struct __tuple_less<0>
1267{
1268 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001269 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270 bool operator()(const _Tp&, const _Up&)
1271 {
1272 return false;
1273 }
1274};
1275
1276template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001277inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278bool
1279operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1280{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001281 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001282 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1283}
1284
1285template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001286inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287bool
1288operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1289{
1290 return __y < __x;
1291}
1292
1293template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001294inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001295bool
1296operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1297{
1298 return !(__x < __y);
1299}
1300
1301template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001302inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303bool
1304operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1305{
1306 return !(__y < __x);
1307}
1308
1309// tuple_cat
1310
Howard Hinnant6256ee72010-12-11 20:47:50 +00001311template <class _Tp, class _Up> struct __tuple_cat_type;
1312
1313template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001314struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001316 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001317};
1318
1319template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1320struct __tuple_cat_return_1
1321{
1322};
1323
1324template <class ..._Types, class _Tuple0>
1325struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1326{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001327 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001328 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001329 type;
1330};
1331
1332template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1333struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1334 : public __tuple_cat_return_1<
1335 typename __tuple_cat_type<
1336 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001337 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001338 >::type,
1339 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1340 _Tuple1, _Tuples...>
1341{
1342};
1343
1344template <class ..._Tuples> struct __tuple_cat_return;
1345
1346template <class _Tuple0, class ..._Tuples>
1347struct __tuple_cat_return<_Tuple0, _Tuples...>
1348 : public __tuple_cat_return_1<tuple<>,
1349 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1350 _Tuples...>
1351{
1352};
1353
1354template <>
1355struct __tuple_cat_return<>
1356{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001357 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001358};
1359
Marshall Clow2229cee2013-07-22 16:02:19 +00001360inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001361tuple<>
1362tuple_cat()
1363{
1364 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001365}
1366
Howard Hinnantc834c512011-11-29 18:15:50 +00001367template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001368struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369
Howard Hinnant21376f62010-12-12 23:04:37 +00001370template <class ..._Types, size_t ..._I0, class _Tuple0>
1371struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001372{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001373 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001374 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1375 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1376};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001377
Howard Hinnant21376f62010-12-12 23:04:37 +00001378template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1379struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1380 _Tuple0, _Tuple1, _Tuples...>
1381 : public __tuple_cat_return_ref_imp<
1382 tuple<_Types..., typename __apply_cv<_Tuple0,
1383 typename tuple_element<_I0,
1384 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1385 typename __make_tuple_indices<tuple_size<typename
1386 remove_reference<_Tuple1>::type>::value>::type,
1387 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001388{
Howard Hinnant21376f62010-12-12 23:04:37 +00001389};
1390
1391template <class _Tuple0, class ..._Tuples>
1392struct __tuple_cat_return_ref
1393 : public __tuple_cat_return_ref_imp<tuple<>,
1394 typename __make_tuple_indices<
1395 tuple_size<typename remove_reference<_Tuple0>::type>::value
1396 >::type, _Tuple0, _Tuples...>
1397{
1398};
1399
1400template <class _Types, class _I0, class _J0>
1401struct __tuple_cat;
1402
1403template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001404struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001405{
1406 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001407 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001408 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1409 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1410 {
David Blaikie699a5e22019-10-28 18:03:59 -07001411 return _VSTD::forward_as_tuple(
1412 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1413 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001414 }
1415
1416 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001417 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001418 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1419 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1420 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001421 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1422 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001423 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001424 tuple<_Types...,
1425 typename __apply_cv<_Tuple0, typename tuple_element<
1426 _J0, _T0>::type>::type&&...>,
1427 typename __make_tuple_indices<sizeof...(_Types) +
1428 tuple_size<_T0>::value>::type,
1429 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1430 _VSTD::forward_as_tuple(
1431 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1432 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1433 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001434 }
1435};
1436
1437template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001438inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001439typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1440tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1441{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001442 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001443 return __tuple_cat<tuple<>, __tuple_indices<>,
1444 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001445 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1446 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447}
1448
1449template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001450struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001451 : true_type {};
1452
Howard Hinnantc51e1022010-05-11 19:42:16 +00001453template <class _T1, class _T2>
1454template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001455inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456pair<_T1, _T2>::pair(piecewise_construct_t,
1457 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1458 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001459 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1460 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001461{
1462}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463
Eric Fiselier8e892c52016-07-18 00:35:56 +00001464#if _LIBCPP_STD_VER > 14
1465template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001466_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001467
1468#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1469
1470template <class _Fn, class _Tuple, size_t ..._Id>
1471inline _LIBCPP_INLINE_VISIBILITY
1472constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1473 __tuple_indices<_Id...>)
1474_LIBCPP_NOEXCEPT_RETURN(
1475 _VSTD::__invoke_constexpr(
1476 _VSTD::forward<_Fn>(__f),
1477 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1478)
1479
1480template <class _Fn, class _Tuple>
1481inline _LIBCPP_INLINE_VISIBILITY
1482constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1483_LIBCPP_NOEXCEPT_RETURN(
1484 _VSTD::__apply_tuple_impl(
1485 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001486 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001487)
1488
1489template <class _Tp, class _Tuple, size_t... _Idx>
1490inline _LIBCPP_INLINE_VISIBILITY
1491constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1492_LIBCPP_NOEXCEPT_RETURN(
1493 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1494)
1495
1496template <class _Tp, class _Tuple>
1497inline _LIBCPP_INLINE_VISIBILITY
1498constexpr _Tp make_from_tuple(_Tuple&& __t)
1499_LIBCPP_NOEXCEPT_RETURN(
1500 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001501 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001502)
1503
1504#undef _LIBCPP_NOEXCEPT_RETURN
1505
1506#endif // _LIBCPP_STD_VER > 14
1507
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001508#endif // !defined(_LIBCPP_CXX03_LANG)
1509
Howard Hinnantc51e1022010-05-11 19:42:16 +00001510_LIBCPP_END_NAMESPACE_STD
1511
1512#endif // _LIBCPP_TUPLE