blob: 0a62578eadbbd493f43daf3cd6271bb42135dde9 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
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
Nikolas Klauserad26ba52022-01-17 19:45:42 +010076
77template<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23
78 requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }
79struct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {
80 using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
81};
82
83template<class... TTypes, class... UTypes> // since C++23
84 requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }
85struct common_type<tuple<TTypes...>, tuple<UTypes...>> {
86 using type = tuple<common_type_t<TTypes, UTypes>...>;
87};
88
Louis Dionne616da2a2019-08-12 18:30:31 +000089template <class ...T>
90tuple(T...) -> tuple<T...>; // since C++17
91template <class T1, class T2>
92tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
93template <class Alloc, class ...T>
94tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
95template <class Alloc, class T1, class T2>
96tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
97template <class Alloc, class ...T>
98tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
99
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000100inline constexpr unspecified ignore;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000101
Marshall Clow2229cee2013-07-22 16:02:19 +0000102template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clowded420b2013-10-05 18:46:37 +0000103template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clowa8892812014-02-25 16:11:46 +0000104template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clow2229cee2013-07-22 16:02:19 +0000105template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier8e892c52016-07-18 00:35:56 +0000106
107// [tuple.apply], calling a function with a tuple of arguments:
108template <class F, class Tuple>
109 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
110template <class T, class Tuple>
111 constexpr T make_from_tuple(Tuple&& t); // C++17
112
Howard Hinnantc51e1022010-05-11 19:42:16 +0000113// 20.4.1.4, tuple helper classes:
Marshall Clowce62b4d2019-01-11 21:57:12 +0000114template <class T> struct tuple_size; // undefined
115template <class... T> struct tuple_size<tuple<T...>>;
Eric Fiselier8e892c52016-07-18 00:35:56 +0000116template <class T>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000117 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Louis Dionnee684aa62019-04-01 16:39:34 +0000118template <size_t I, class T> struct tuple_element; // undefined
119template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
Marshall Clow36907512015-11-19 19:45:29 +0000120template <size_t I, class T>
121 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000122
123// 20.4.1.5, element access:
Marshall Clow36907512015-11-19 19:45:29 +0000124template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000125 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000126 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000127template <size_t I, class... T>
128 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000129 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000130template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000131 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow0abb1042013-07-17 18:25:36 +0000132 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000133template <size_t I, class... T>
134 const typename tuple_element<I, tuple<T...>>::type&&
135 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136
Marshall Clow15b02e02013-07-13 02:54:05 +0000137template <class T1, class... T>
138 constexpr T1& get(tuple<T...>&) noexcept; // C++14
139template <class T1, class... T>
Marshall Clow36907512015-11-19 19:45:29 +0000140 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000141template <class T1, class... T>
142 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000143template <class T1, class... T>
144 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000145
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146// 20.4.1.6, relational operators:
Marshall Clow2229cee2013-07-22 16:02:19 +0000147template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Kent Ross0861b0d2021-10-08 14:54:28 -0700148template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
149template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
150template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
151template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
152template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
153template<class... T, class... U>
154 constexpr common_comparison_category_t<synth-three-way-result<T, U>...>
155 operator<=>(const tuple<T...>&, const tuple<U...>&); // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156
157template <class... Types, class Alloc>
158 struct uses_allocator<tuple<Types...>, Alloc>;
159
160template <class... Types>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000161 void
162 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164} // std
165
166*/
167
Louis Dionneb4fce352022-03-25 12:55:36 -0400168#include <__assert> // all public C++ headers provide the assertion handler
Kent Ross0861b0d2021-10-08 14:54:28 -0700169#include <__compare/common_comparison_category.h>
170#include <__compare/synth_three_way.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000171#include <__config>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000172#include <__functional/unwrap_ref.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400173#include <__memory/allocator_arg_t.h>
174#include <__memory/uses_allocator.h>
175#include <__tuple>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000176#include <__utility/forward.h>
Kent Ross0861b0d2021-10-08 14:54:28 -0700177#include <__utility/integer_sequence.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000178#include <__utility/move.h>
Nikolas Klauser8fccd622022-03-05 19:17:07 +0100179#include <__utility/pair.h>
180#include <__utility/piecewise_construct.h>
181#include <__utility/swap.h>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400182#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000183#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000185#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186
Nikolas Klauser4c1bf592022-02-11 19:15:18 +0100187// TODO: remove these headers
188#include <__functional/binary_function.h>
189#include <__functional/invoke.h>
190#include <__functional/operations.h>
191#include <__functional/reference_wrapper.h>
192#include <__functional/unary_function.h>
193#include <__functional/weak_result_type.h>
194#include <exception>
195#include <new>
196#include <typeinfo>
197
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000198#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500199# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000200#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201
202_LIBCPP_BEGIN_NAMESPACE_STD
203
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000204#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205
Marshall Clowf50d66f2014-03-03 06:18:11 +0000206
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207// __tuple_leaf
208
Eric Fiselierf7394302015-06-13 07:08:02 +0000209template <size_t _Ip, class _Hp,
210 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000211 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212class __tuple_leaf;
213
214template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500215inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000217 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218{
219 swap(__x.get(), __y.get());
220}
221
222template <size_t _Ip, class _Hp, bool>
223class __tuple_leaf
224{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000225 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226
Eric Fiselierca8bba12016-07-20 02:57:39 +0000227 template <class _Tp>
228 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000229#if __has_keyword(__reference_binds_to_temporary)
230 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000231#else
232 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000233#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000234 }
235
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500236 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237 __tuple_leaf& operator=(const __tuple_leaf&);
238public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500239 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000240 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000241 {static_assert(!is_reference<_Hp>::value,
242 "Attempted to default construct a reference element in a tuple");}
243
244 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500245 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000247 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000248 {static_assert(!is_reference<_Hp>::value,
249 "Attempted to default construct a reference element in a tuple");}
250
251 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500252 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000254 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255 {static_assert(!is_reference<_Hp>::value,
256 "Attempted to default construct a reference element in a tuple");}
257
258 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500259 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000261 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262 {static_assert(!is_reference<_Hp>::value,
263 "Attempted to default construct a reference element in a tuple");}
264
Howard Hinnant693fc212010-09-27 17:54:17 +0000265 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400266 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000267 _And<
268 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
269 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000270 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000271 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000272 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000273 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000274 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000275 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000276 {static_assert(__can_bind_reference<_Tp&&>(),
277 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278
279 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500280 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000282 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000283 {static_assert(__can_bind_reference<_Tp&&>(),
284 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285
286 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000289 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000290 {static_assert(!is_reference<_Hp>::value,
291 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292
293 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500294 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000296 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000297 {static_assert(!is_reference<_Hp>::value,
298 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000299
Marshall Clow47fcee52014-04-21 23:48:09 +0000300 __tuple_leaf(const __tuple_leaf& __t) = default;
301 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500303 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000304 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000306 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000307 return 0;
308 }
309
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000310 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
311 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312};
313
314template <size_t _Ip, class _Hp>
315class __tuple_leaf<_Ip, _Hp, true>
316 : private _Hp
317{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500318 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000319 __tuple_leaf& operator=(const __tuple_leaf&);
320public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500321 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000322 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000323
324 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500325 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
327
328 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500329 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
331 : _Hp(allocator_arg_t(), __a) {}
332
333 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500334 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000335 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
336 : _Hp(__a) {}
337
Howard Hinnant693fc212010-09-27 17:54:17 +0000338 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400339 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000340 _And<
341 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
342 is_constructible<_Hp, _Tp>
343 >::value
344 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000345 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000346 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000347 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000348 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349
350 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500351 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000353 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354
355 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500356 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000358 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359
360 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500361 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000363 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000365 __tuple_leaf(__tuple_leaf const &) = default;
366 __tuple_leaf(__tuple_leaf &&) = default;
367
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500368 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000369 int
370 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000371 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000372 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373 return 0;
374 }
375
Marshall Clow2229cee2013-07-22 16:02:19 +0000376 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
377 _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 +0000378};
379
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000380template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500381_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000382void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383
Marshall Clowc470eae2014-10-15 10:33:02 +0000384template <class _Tp>
385struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000386
Marshall Clowc470eae2014-10-15 10:33:02 +0000387template <class ..._Tp>
388struct __all_default_constructible<__tuple_types<_Tp...>>
389 : __all<is_default_constructible<_Tp>::value...>
390{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000391
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392// __tuple_impl
393
394template<class _Indx, class ..._Tp> struct __tuple_impl;
395
396template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000397struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398 : public __tuple_leaf<_Indx, _Tp>...
399{
Howard Hinnant38469632012-07-06 20:39:45 +0000400 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500401 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000402 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000403
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404 template <size_t ..._Uf, class ..._Tf,
405 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000406 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407 explicit
408 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
409 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000410 _Up&&... __u)
411 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
412 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000413 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000414 __tuple_leaf<_Ul, _Tl>()...
415 {}
416
417 template <class _Alloc, size_t ..._Uf, class ..._Tf,
418 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500419 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420 explicit
421 __tuple_impl(allocator_arg_t, const _Alloc& __a,
422 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
423 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
424 _Up&&... __u) :
425 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000426 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
428 {}
429
430 template <class _Tuple,
431 class = typename enable_if
432 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000433 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434 >::type
435 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000436 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000437 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
438 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000439 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
440 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441 {}
442
443 template <class _Alloc, class _Tuple,
444 class = typename enable_if
445 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000446 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447 >::type
448 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500449 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
451 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000452 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000453 _VSTD::forward<typename tuple_element<_Indx,
454 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000455 {}
456
Howard Hinnant0d032d12013-11-06 17:45:43 +0000457 __tuple_impl(const __tuple_impl&) = default;
458 __tuple_impl(__tuple_impl&&) = default;
459
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500460 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000462 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400464 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000465 }
466};
467
Louis Dionne6c0d5342018-07-31 11:56:20 -0400468template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500469_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400470void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
471 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
472}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000473
Louis Dionne6c0d5342018-07-31 11:56:20 -0400474template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500475_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400476void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
477 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500478 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400479 ), void(), 0)...);
480}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000481
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000483class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000485 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000487 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488
Marshall Clow0abb1042013-07-17 18:25:36 +0000489 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000490 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000491 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000492 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000493 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000494 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000495 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
496 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500498 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499
Louis Dionne574e2e32021-02-10 16:19:50 -0500500 // tuple() constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400501 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500502 _And<
503 _IsImpDefault<_Tp>... // explicit check
504 >::value
505 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400506 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000507 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500508 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
509 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000510
Louis Dionne574e2e32021-02-10 16:19:50 -0500511 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400512 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500513 _And<
514 _IsDefault<_Tp>...,
515 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
516 >::value
517 , int> = 0>
518 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
519 explicit tuple()
520 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
521 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000522
Louis Dionne9ce598d2021-09-08 09:14:43 -0400523 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500524 _And<
525 _IsImpDefault<_Tp>... // explicit check
526 >::value
527 , int> = 0>
528 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
529 tuple(allocator_arg_t, _Alloc const& __a)
530 : __base_(allocator_arg_t(), __a,
531 __tuple_indices<>(), __tuple_types<>(),
532 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
533 __tuple_types<_Tp...>()) {}
534
535 template <class _Alloc,
536 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400537 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500538 _And<
539 _IsDefault<_Tp>...,
540 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
541 >::value
542 , int> = 0>
543 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
544 explicit tuple(allocator_arg_t, _Alloc const& __a)
545 : __base_(allocator_arg_t(), __a,
546 __tuple_indices<>(), __tuple_types<>(),
547 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
548 __tuple_types<_Tp...>()) {}
549
550 // tuple(const T&...) constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400551 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500552 _And<
553 _BoolConstant<sizeof...(_Tp) >= 1>,
554 is_copy_constructible<_Tp>...,
555 is_convertible<const _Tp&, _Tp>... // explicit check
556 >::value
557 , int> = 0>
558 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
559 tuple(const _Tp& ... __t)
560 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
561 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
562 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
563 typename __make_tuple_indices<0>::type(),
564 typename __make_tuple_types<tuple, 0>::type(),
565 __t...
566 ) {}
567
Louis Dionne9ce598d2021-09-08 09:14:43 -0400568 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500569 _And<
570 _BoolConstant<sizeof...(_Tp) >= 1>,
571 is_copy_constructible<_Tp>...,
572 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
573 >::value
574 , int> = 0>
575 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
576 explicit tuple(const _Tp& ... __t)
577 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
578 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
579 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
580 typename __make_tuple_indices<0>::type(),
581 typename __make_tuple_types<tuple, 0>::type(),
582 __t...
583 ) {}
584
Louis Dionne9ce598d2021-09-08 09:14:43 -0400585 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500586 _And<
587 _BoolConstant<sizeof...(_Tp) >= 1>,
588 is_copy_constructible<_Tp>...,
589 is_convertible<const _Tp&, _Tp>... // explicit check
590 >::value
591 , int> = 0>
592 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
593 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
594 : __base_(allocator_arg_t(), __a,
595 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
596 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
597 typename __make_tuple_indices<0>::type(),
598 typename __make_tuple_types<tuple, 0>::type(),
599 __t...
600 ) {}
601
Louis Dionne9ce598d2021-09-08 09:14:43 -0400602 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500603 _And<
604 _BoolConstant<sizeof...(_Tp) >= 1>,
605 is_copy_constructible<_Tp>...,
606 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
607 >::value
608 , int> = 0>
609 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
610 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
611 : __base_(allocator_arg_t(), __a,
612 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
613 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
614 typename __make_tuple_indices<0>::type(),
615 typename __make_tuple_types<tuple, 0>::type(),
616 __t...
617 ) {}
618
619 // tuple(U&& ...) constructors (including allocator_arg_t variants)
620 template <class ..._Up> struct _IsThisTuple : false_type { };
621 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
622
623 template <class ..._Up>
624 struct _EnableUTypesCtor : _And<
625 _BoolConstant<sizeof...(_Tp) >= 1>,
626 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
627 is_constructible<_Tp, _Up>...
628 > { };
629
Louis Dionne9ce598d2021-09-08 09:14:43 -0400630 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500631 _And<
632 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
633 _EnableUTypesCtor<_Up...>,
634 is_convertible<_Up, _Tp>... // explicit check
635 >::value
636 , int> = 0>
637 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
638 tuple(_Up&&... __u)
639 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
640 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
641 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
642 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
643 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
644 _VSTD::forward<_Up>(__u)...) {}
645
Louis Dionne9ce598d2021-09-08 09:14:43 -0400646 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500647 _And<
648 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
649 _EnableUTypesCtor<_Up...>,
650 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
651 >::value
652 , int> = 0>
653 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
654 explicit tuple(_Up&&... __u)
655 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
656 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
657 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
658 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
659 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
660 _VSTD::forward<_Up>(__u)...) {}
661
Louis Dionne9ce598d2021-09-08 09:14:43 -0400662 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500663 _And<
664 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
665 _EnableUTypesCtor<_Up...>,
666 is_convertible<_Up, _Tp>... // explicit check
667 >::value
668 , int> = 0>
669 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
670 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
671 : __base_(allocator_arg_t(), __a,
672 typename __make_tuple_indices<sizeof...(_Up)>::type(),
673 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
674 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
675 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
676 _VSTD::forward<_Up>(__u)...) {}
677
Louis Dionne9ce598d2021-09-08 09:14:43 -0400678 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500679 _And<
680 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
681 _EnableUTypesCtor<_Up...>,
682 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
683 >::value
684 , int> = 0>
685 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
686 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
687 : __base_(allocator_arg_t(), __a,
688 typename __make_tuple_indices<sizeof...(_Up)>::type(),
689 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
690 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
691 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
692 _VSTD::forward<_Up>(__u)...) {}
693
694 // Copy and move constructors (including the allocator_arg_t variants)
695 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000696 tuple(tuple&&) = default;
697
Louis Dionne9ce598d2021-09-08 09:14:43 -0400698 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500699 _And<is_copy_constructible<_Tp>...>::value
700 , int> = 0>
701 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
702 : __base_(allocator_arg_t(), __alloc, __t)
703 { }
704
Louis Dionne9ce598d2021-09-08 09:14:43 -0400705 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500706 _And<is_move_constructible<_Tp>...>::value
707 , int> = 0>
708 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
709 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
710 { }
711
712 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
713 template <class ..._Up>
714 struct _EnableCopyFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400715 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
716 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500717 _BoolConstant<sizeof...(_Tp) != 1>,
718 // _Tp and _Up are 1-element packs - the pack expansions look
719 // weird to avoid tripping up the type traits in degenerate cases
720 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500721 _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
722 _Not<is_constructible<_Tp, const tuple<_Up>&> >...
723 >
724 >,
725 is_constructible<_Tp, const _Up&>...
726 > { };
727
Louis Dionne9ce598d2021-09-08 09:14:43 -0400728 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500729 _And<
730 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
731 _EnableCopyFromOtherTuple<_Up...>,
732 is_convertible<const _Up&, _Tp>... // explicit check
733 >::value
734 , int> = 0>
735 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
736 tuple(const tuple<_Up...>& __t)
737 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
738 : __base_(__t)
739 { }
740
Louis Dionne9ce598d2021-09-08 09:14:43 -0400741 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500742 _And<
743 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
744 _EnableCopyFromOtherTuple<_Up...>,
745 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
746 >::value
747 , int> = 0>
748 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
749 explicit tuple(const tuple<_Up...>& __t)
750 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
751 : __base_(__t)
752 { }
753
Louis Dionne9ce598d2021-09-08 09:14:43 -0400754 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500755 _And<
756 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
757 _EnableCopyFromOtherTuple<_Up...>,
758 is_convertible<const _Up&, _Tp>... // explicit check
759 >::value
760 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500761 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500762 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
763 : __base_(allocator_arg_t(), __a, __t)
764 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000765
Louis Dionne9ce598d2021-09-08 09:14:43 -0400766 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500767 _And<
768 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
769 _EnableCopyFromOtherTuple<_Up...>,
770 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
771 >::value
772 , int> = 0>
773 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
774 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
775 : __base_(allocator_arg_t(), __a, __t)
776 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000777
Louis Dionne574e2e32021-02-10 16:19:50 -0500778 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
779 template <class ..._Up>
780 struct _EnableMoveFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400781 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
782 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500783 _BoolConstant<sizeof...(_Tp) != 1>,
784 // _Tp and _Up are 1-element packs - the pack expansions look
785 // weird to avoid tripping up the type traits in degenerate cases
786 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500787 _Not<is_convertible<tuple<_Up>, _Tp> >...,
788 _Not<is_constructible<_Tp, tuple<_Up> > >...
789 >
790 >,
791 is_constructible<_Tp, _Up>...
792 > { };
793
Louis Dionne9ce598d2021-09-08 09:14:43 -0400794 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500795 _And<
796 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
797 _EnableMoveFromOtherTuple<_Up...>,
798 is_convertible<_Up, _Tp>... // explicit check
799 >::value
800 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000801 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500802 tuple(tuple<_Up...>&& __t)
803 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
804 : __base_(_VSTD::move(__t))
805 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806
Louis Dionne9ce598d2021-09-08 09:14:43 -0400807 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500808 _And<
809 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
810 _EnableMoveFromOtherTuple<_Up...>,
811 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
812 >::value
813 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000814 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500815 explicit tuple(tuple<_Up...>&& __t)
816 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
817 : __base_(_VSTD::move(__t))
818 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000819
Louis Dionne9ce598d2021-09-08 09:14:43 -0400820 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500821 _And<
822 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
823 _EnableMoveFromOtherTuple<_Up...>,
824 is_convertible<_Up, _Tp>... // explicit check
825 >::value
826 , int> = 0>
827 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
828 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
829 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
830 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831
Louis Dionne9ce598d2021-09-08 09:14:43 -0400832 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500833 _And<
834 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
835 _EnableMoveFromOtherTuple<_Up...>,
836 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
837 >::value
838 , int> = 0>
839 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
840 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
841 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
842 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000843
Louis Dionne574e2e32021-02-10 16:19:50 -0500844 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
845 template <class _Up1, class _Up2, class ..._DependentTp>
846 struct _EnableImplicitCopyFromPair : _And<
847 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
848 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
849 is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
850 is_convertible<const _Up2&, _SecondType<_DependentTp...> >
851 > { };
Howard Hinnant65704d02012-04-01 23:10:42 +0000852
Louis Dionne574e2e32021-02-10 16:19:50 -0500853 template <class _Up1, class _Up2, class ..._DependentTp>
854 struct _EnableExplicitCopyFromPair : _And<
855 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
856 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
857 _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
858 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
859 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860
Louis Dionne9ce598d2021-09-08 09:14:43 -0400861 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500862 _And<
863 _BoolConstant<sizeof...(_Tp) == 2>,
864 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
865 >::value
866 , int> = 0>
867 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
868 tuple(const pair<_Up1, _Up2>& __p)
869 _NOEXCEPT_((_And<
870 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
871 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
872 >::value))
873 : __base_(__p)
874 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875
Louis Dionne9ce598d2021-09-08 09:14:43 -0400876 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500877 _And<
878 _BoolConstant<sizeof...(_Tp) == 2>,
879 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
880 >::value
881 , int> = 0>
882 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
883 explicit tuple(const pair<_Up1, _Up2>& __p)
884 _NOEXCEPT_((_And<
885 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
886 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
887 >::value))
888 : __base_(__p)
889 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000890
Louis Dionne9ce598d2021-09-08 09:14:43 -0400891 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500892 _And<
893 _BoolConstant<sizeof...(_Tp) == 2>,
894 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
895 >::value
896 , int> = 0>
897 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
898 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
899 : __base_(allocator_arg_t(), __a, __p)
900 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901
Louis Dionne9ce598d2021-09-08 09:14:43 -0400902 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500903 _And<
904 _BoolConstant<sizeof...(_Tp) == 2>,
905 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
906 >::value
907 , int> = 0>
908 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
909 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
910 : __base_(allocator_arg_t(), __a, __p)
911 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000912
Louis Dionne574e2e32021-02-10 16:19:50 -0500913 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
914 template <class _Up1, class _Up2, class ..._DependentTp>
915 struct _EnableImplicitMoveFromPair : _And<
916 is_constructible<_FirstType<_DependentTp...>, _Up1>,
917 is_constructible<_SecondType<_DependentTp...>, _Up2>,
918 is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
919 is_convertible<_Up2, _SecondType<_DependentTp...> >
920 > { };
Eric Fiselierec5a2102019-07-12 23:01:48 +0000921
Louis Dionne574e2e32021-02-10 16:19:50 -0500922 template <class _Up1, class _Up2, class ..._DependentTp>
923 struct _EnableExplicitMoveFromPair : _And<
924 is_constructible<_FirstType<_DependentTp...>, _Up1>,
925 is_constructible<_SecondType<_DependentTp...>, _Up2>,
926 _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
927 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
928 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000929
Louis Dionne9ce598d2021-09-08 09:14:43 -0400930 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500931 _And<
932 _BoolConstant<sizeof...(_Tp) == 2>,
933 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
934 >::value
935 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400936 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500937 tuple(pair<_Up1, _Up2>&& __p)
938 _NOEXCEPT_((_And<
939 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
940 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
941 >::value))
942 : __base_(_VSTD::move(__p))
943 { }
944
Louis Dionne9ce598d2021-09-08 09:14:43 -0400945 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500946 _And<
947 _BoolConstant<sizeof...(_Tp) == 2>,
948 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
949 >::value
950 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400951 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500952 explicit tuple(pair<_Up1, _Up2>&& __p)
953 _NOEXCEPT_((_And<
954 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
955 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
956 >::value))
957 : __base_(_VSTD::move(__p))
958 { }
959
Louis Dionne9ce598d2021-09-08 09:14:43 -0400960 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500961 _And<
962 _BoolConstant<sizeof...(_Tp) == 2>,
963 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
964 >::value
965 , int> = 0>
966 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
967 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
968 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
969 { }
970
Louis Dionne9ce598d2021-09-08 09:14:43 -0400971 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500972 _And<
973 _BoolConstant<sizeof...(_Tp) == 2>,
974 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
975 >::value
976 , int> = 0>
977 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
978 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
979 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
980 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000981
Louis Dionne6c0d5342018-07-31 11:56:20 -0400982 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500983 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400984 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
985 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000986 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400987 _VSTD::__memberwise_copy_assign(*this, __tuple,
988 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000989 return *this;
990 }
991
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500992 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400993 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
994 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000995 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400996 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
997 __tuple_types<_Tp...>(),
998 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000999 return *this;
1000 }
1001
Louis Dionne9ce598d2021-09-08 09:14:43 -04001002 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001003 _And<
1004 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1005 is_assignable<_Tp&, _Up const&>...
1006 >::value
1007 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001008 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001009 tuple& operator=(tuple<_Up...> const& __tuple)
1010 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1011 {
1012 _VSTD::__memberwise_copy_assign(*this, __tuple,
1013 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1014 return *this;
1015 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016
Louis Dionne9ce598d2021-09-08 09:14:43 -04001017 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001018 _And<
1019 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1020 is_assignable<_Tp&, _Up>...
1021 >::value
1022 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001023 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001024 tuple& operator=(tuple<_Up...>&& __tuple)
1025 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1026 {
1027 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1028 __tuple_types<_Up...>(),
1029 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1030 return *this;
1031 }
1032
Louis Dionne9ce598d2021-09-08 09:14:43 -04001033 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001034 _And<_Dep,
1035 _BoolConstant<sizeof...(_Tp) == 2>,
1036 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1037 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1038 >::value
1039 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001040 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001041 tuple& operator=(pair<_Up1, _Up2> const& __pair)
1042 _NOEXCEPT_((_And<
1043 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1044 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1045 >::value))
1046 {
1047 _VSTD::get<0>(*this) = __pair.first;
1048 _VSTD::get<1>(*this) = __pair.second;
1049 return *this;
1050 }
1051
Louis Dionne9ce598d2021-09-08 09:14:43 -04001052 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001053 _And<_Dep,
1054 _BoolConstant<sizeof...(_Tp) == 2>,
1055 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1056 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1057 >::value
1058 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001059 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001060 tuple& operator=(pair<_Up1, _Up2>&& __pair)
1061 _NOEXCEPT_((_And<
1062 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1063 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1064 >::value))
1065 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001066 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1067 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001068 return *this;
1069 }
1070
1071 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001072 template<class _Up, size_t _Np, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001073 _And<
1074 _BoolConstant<_Np == sizeof...(_Tp)>,
1075 is_assignable<_Tp&, _Up const&>...
1076 >::value
1077 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001078 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001079 tuple& operator=(array<_Up, _Np> const& __array)
1080 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1081 {
1082 _VSTD::__memberwise_copy_assign(*this, __array,
1083 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1084 return *this;
1085 }
1086
1087 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001088 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001089 _And<
1090 _BoolConstant<_Np == sizeof...(_Tp)>,
1091 is_assignable<_Tp&, _Up>...
1092 >::value
1093 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001095 tuple& operator=(array<_Up, _Np>&& __array)
1096 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1097 {
1098 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1099 __tuple_types<_If<true, _Up, _Tp>...>(),
1100 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1101 return *this;
1102 }
1103
1104 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001105 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001106 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001107 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108};
1109
1110template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001111class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001112{
1113public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001114 _LIBCPP_INLINE_VISIBILITY constexpr
1115 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001117 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001118 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001120 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001121 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001122 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001123 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001124 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001125 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001126 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001127 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001128 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001129 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130};
1131
Joe Loserd9b3d972022-03-12 10:46:57 -05001132#if _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001133template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1134 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1135struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1136 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1137};
1138
1139template <class... _TTypes, class... _UTypes>
1140 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1141struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1142 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1143};
Joe Loserd9b3d972022-03-12 10:46:57 -05001144#endif // _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001145
1146#if _LIBCPP_STD_VER > 14
Louis Dionne616da2a2019-08-12 18:30:31 +00001147template <class ..._Tp>
1148tuple(_Tp...) -> tuple<_Tp...>;
1149template <class _Tp1, class _Tp2>
1150tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1151template <class _Alloc, class ..._Tp>
1152tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1153template <class _Alloc, class _Tp1, class _Tp2>
1154tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1155template <class _Alloc, class ..._Tp>
1156tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001157#endif
1158
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001160inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001161typename enable_if
1162<
1163 __all<__is_swappable<_Tp>::value...>::value,
1164 void
1165>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001166swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1167 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1168 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001169
1170// get
1171
1172template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001173inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001174typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001175get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001177 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001178 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179}
1180
1181template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001182inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001183const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001184get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001185{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001186 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001187 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188}
1189
Howard Hinnant22e97242010-11-17 19:52:17 +00001190template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001191inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001192typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001193get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001194{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001195 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001196 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001197 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001198}
1199
Eric Fiselier6dea8092015-12-18 00:36:55 +00001200template <size_t _Ip, class ..._Tp>
1201inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1202const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1203get(const tuple<_Tp...>&& __t) _NOEXCEPT
1204{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001205 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001206 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001207 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001208}
1209
Marshall Clow15b02e02013-07-13 02:54:05 +00001210#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001211
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001212namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001213
Louis Dionne7dd28aa2021-07-20 11:46:05 -04001214static constexpr size_t __not_found = static_cast<size_t>(-1);
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001215static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001216
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001217inline _LIBCPP_INLINE_VISIBILITY
1218constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1219 return !__matches ? __res :
1220 (__res == __not_found ? __curr_i : __ambiguous);
1221}
Marshall Clow15b02e02013-07-13 02:54:05 +00001222
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001223template <size_t _Nx>
1224inline _LIBCPP_INLINE_VISIBILITY
1225constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1226 return __i == _Nx ? __not_found :
1227 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1228}
1229
1230template <class _T1, class ..._Args>
1231struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001232 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001233 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001234 static_assert(value != __not_found, "type not found in type list" );
1235 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001236};
1237
Eric Fiselier8087d302016-07-02 03:46:08 +00001238template <class _T1>
1239struct __find_exactly_one_checked<_T1> {
1240 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1241};
1242
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001243} // namespace __find_detail
Marshall Clow15b02e02013-07-13 02:54:05 +00001244
1245template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001246struct __find_exactly_one_t
1247 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1248};
Marshall Clow15b02e02013-07-13 02:54:05 +00001249
1250template <class _T1, class... _Args>
1251inline _LIBCPP_INLINE_VISIBILITY
1252constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1253{
1254 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1255}
1256
1257template <class _T1, class... _Args>
1258inline _LIBCPP_INLINE_VISIBILITY
1259constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1260{
1261 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1262}
1263
1264template <class _T1, class... _Args>
1265inline _LIBCPP_INLINE_VISIBILITY
1266constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1267{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001268 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001269}
1270
Eric Fiselier6dea8092015-12-18 00:36:55 +00001271template <class _T1, class... _Args>
1272inline _LIBCPP_INLINE_VISIBILITY
1273constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1274{
1275 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1276}
1277
Marshall Clow15b02e02013-07-13 02:54:05 +00001278#endif
1279
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280// tie
1281
1282template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001283inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001284tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001285tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286{
1287 return tuple<_Tp&...>(__t...);
1288}
1289
1290template <class _Up>
1291struct __ignore_t
1292{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001294 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1295 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296};
1297
Eric Fiselier24e70262017-02-06 01:25:31 +00001298namespace {
Louis Dionne559be102021-09-22 09:35:32 -04001299 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001300} // namespace
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301
Howard Hinnantc51e1022010-05-11 19:42:16 +00001302template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001303inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001304tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305make_tuple(_Tp&&... __t)
1306{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001307 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308}
1309
Howard Hinnant3d203a32010-08-19 18:59:38 +00001310template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001311inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1312tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001313forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001314{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001315 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001316}
1317
Howard Hinnantc834c512011-11-29 18:15:50 +00001318template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001319struct __tuple_equal
1320{
1321 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001322 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323 bool operator()(const _Tp& __x, const _Up& __y)
1324 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001325 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001326 }
1327};
1328
1329template <>
1330struct __tuple_equal<0>
1331{
1332 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001333 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001334 bool operator()(const _Tp&, const _Up&)
1335 {
1336 return true;
1337 }
1338};
1339
1340template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001341inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001342bool
1343operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1344{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001345 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1347}
1348
Joe Loserd9b3d972022-03-12 10:46:57 -05001349#if _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001350
1351// operator<=>
1352
1353template <class ..._Tp, class ..._Up, size_t ..._Is>
1354_LIBCPP_HIDE_FROM_ABI constexpr
1355auto
1356__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1357 common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1358 static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1359 return __result;
1360}
1361
1362template <class ..._Tp, class ..._Up>
1363requires (sizeof...(_Tp) == sizeof...(_Up))
1364_LIBCPP_HIDE_FROM_ABI constexpr
1365common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1366operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1367{
1368 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1369}
1370
Joe Loserd9b3d972022-03-12 10:46:57 -05001371#else // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001372
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001374inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375bool
1376operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1377{
1378 return !(__x == __y);
1379}
1380
Howard Hinnantc834c512011-11-29 18:15:50 +00001381template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382struct __tuple_less
1383{
1384 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001385 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001386 bool operator()(const _Tp& __x, const _Up& __y)
1387 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001388 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1389 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1390 return true;
1391 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1392 return false;
1393 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001394 }
1395};
1396
1397template <>
1398struct __tuple_less<0>
1399{
1400 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001401 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001402 bool operator()(const _Tp&, const _Up&)
1403 {
1404 return false;
1405 }
1406};
1407
1408template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001409inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001410bool
1411operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1412{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001413 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1415}
1416
1417template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001418inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419bool
1420operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1421{
1422 return __y < __x;
1423}
1424
1425template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001426inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427bool
1428operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1429{
1430 return !(__x < __y);
1431}
1432
1433template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001434inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001435bool
1436operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1437{
1438 return !(__y < __x);
1439}
1440
Joe Loserd9b3d972022-03-12 10:46:57 -05001441#endif // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001442
Howard Hinnantc51e1022010-05-11 19:42:16 +00001443// tuple_cat
1444
Howard Hinnant6256ee72010-12-11 20:47:50 +00001445template <class _Tp, class _Up> struct __tuple_cat_type;
1446
1447template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001448struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001449{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001450 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001451};
1452
1453template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1454struct __tuple_cat_return_1
1455{
1456};
1457
1458template <class ..._Types, class _Tuple0>
1459struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1460{
Nikolas Klauser669b4452022-02-17 22:53:20 +01001461 using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
1462 tuple<_Types...>,
1463 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
1464 >::type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001465};
1466
1467template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1468struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1469 : public __tuple_cat_return_1<
1470 typename __tuple_cat_type<
1471 tuple<_Types...>,
Nikolas Klauser669b4452022-02-17 22:53:20 +01001472 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001473 >::type,
1474 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1475 _Tuple1, _Tuples...>
1476{
1477};
1478
1479template <class ..._Tuples> struct __tuple_cat_return;
1480
1481template <class _Tuple0, class ..._Tuples>
1482struct __tuple_cat_return<_Tuple0, _Tuples...>
1483 : public __tuple_cat_return_1<tuple<>,
1484 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1485 _Tuples...>
1486{
1487};
1488
1489template <>
1490struct __tuple_cat_return<>
1491{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001492 typedef _LIBCPP_NODEBUG tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001493};
1494
Marshall Clow2229cee2013-07-22 16:02:19 +00001495inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001496tuple<>
1497tuple_cat()
1498{
1499 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500}
1501
Howard Hinnantc834c512011-11-29 18:15:50 +00001502template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001503struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504
Howard Hinnant21376f62010-12-12 23:04:37 +00001505template <class ..._Types, size_t ..._I0, class _Tuple0>
1506struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001508 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001509 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1510 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1511};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512
Howard Hinnant21376f62010-12-12 23:04:37 +00001513template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1514struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1515 _Tuple0, _Tuple1, _Tuples...>
1516 : public __tuple_cat_return_ref_imp<
1517 tuple<_Types..., typename __apply_cv<_Tuple0,
1518 typename tuple_element<_I0,
1519 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1520 typename __make_tuple_indices<tuple_size<typename
1521 remove_reference<_Tuple1>::type>::value>::type,
1522 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001523{
Howard Hinnant21376f62010-12-12 23:04:37 +00001524};
1525
1526template <class _Tuple0, class ..._Tuples>
1527struct __tuple_cat_return_ref
1528 : public __tuple_cat_return_ref_imp<tuple<>,
1529 typename __make_tuple_indices<
1530 tuple_size<typename remove_reference<_Tuple0>::type>::value
1531 >::type, _Tuple0, _Tuples...>
1532{
1533};
1534
1535template <class _Types, class _I0, class _J0>
1536struct __tuple_cat;
1537
1538template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001539struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001540{
1541 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001542 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001543 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1544 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1545 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001546 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
David Blaikie699a5e22019-10-28 18:03:59 -07001547 return _VSTD::forward_as_tuple(
1548 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1549 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001550 }
1551
1552 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001553 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001554 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1555 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1556 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001557 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001558 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1559 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001560 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001561 tuple<_Types...,
1562 typename __apply_cv<_Tuple0, typename tuple_element<
1563 _J0, _T0>::type>::type&&...>,
1564 typename __make_tuple_indices<sizeof...(_Types) +
1565 tuple_size<_T0>::value>::type,
1566 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1567 _VSTD::forward_as_tuple(
1568 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1569 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1570 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001571 }
1572};
1573
1574template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001575inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001576typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1577tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1578{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001579 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001580 return __tuple_cat<tuple<>, __tuple_indices<>,
1581 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001582 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1583 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584}
1585
1586template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001587struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001588 : true_type {};
1589
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590template <class _T1, class _T2>
1591template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001592inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001593pair<_T1, _T2>::pair(piecewise_construct_t,
1594 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1595 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001596 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1597 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598{
1599}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600
Eric Fiselier8e892c52016-07-18 00:35:56 +00001601#if _LIBCPP_STD_VER > 14
1602template <class _Tp>
Louis Dionne559be102021-09-22 09:35:32 -04001603inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001604
1605#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1606
1607template <class _Fn, class _Tuple, size_t ..._Id>
1608inline _LIBCPP_INLINE_VISIBILITY
1609constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1610 __tuple_indices<_Id...>)
1611_LIBCPP_NOEXCEPT_RETURN(
1612 _VSTD::__invoke_constexpr(
1613 _VSTD::forward<_Fn>(__f),
1614 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1615)
1616
1617template <class _Fn, class _Tuple>
1618inline _LIBCPP_INLINE_VISIBILITY
1619constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1620_LIBCPP_NOEXCEPT_RETURN(
1621 _VSTD::__apply_tuple_impl(
1622 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001623 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001624)
1625
1626template <class _Tp, class _Tuple, size_t... _Idx>
1627inline _LIBCPP_INLINE_VISIBILITY
1628constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1629_LIBCPP_NOEXCEPT_RETURN(
1630 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1631)
1632
1633template <class _Tp, class _Tuple>
1634inline _LIBCPP_INLINE_VISIBILITY
1635constexpr _Tp make_from_tuple(_Tuple&& __t)
1636_LIBCPP_NOEXCEPT_RETURN(
1637 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001638 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001639)
1640
1641#undef _LIBCPP_NOEXCEPT_RETURN
1642
1643#endif // _LIBCPP_STD_VER > 14
1644
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001645#endif // !defined(_LIBCPP_CXX03_LANG)
1646
Howard Hinnantc51e1022010-05-11 19:42:16 +00001647_LIBCPP_END_NAMESPACE_STD
1648
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001649#endif // _LIBCPP_TUPLE