blob: ab1202d43ddfd012f514c84496edec1103d4611b [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
Kent Ross0861b0d2021-10-08 14:54:28 -0700168#include <__compare/common_comparison_category.h>
169#include <__compare/synth_three_way.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170#include <__config>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000171#include <__functional/unwrap_ref.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400172#include <__memory/allocator_arg_t.h>
173#include <__memory/uses_allocator.h>
174#include <__tuple>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000175#include <__utility/forward.h>
Kent Ross0861b0d2021-10-08 14:54:28 -0700176#include <__utility/integer_sequence.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000177#include <__utility/move.h>
Nikolas Klauser8fccd622022-03-05 19:17:07 +0100178#include <__utility/pair.h>
179#include <__utility/piecewise_construct.h>
180#include <__utility/swap.h>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400181#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000183#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000184#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185
Nikolas Klauser8fccd622022-03-05 19:17:07 +0100186#include <utility> // TODO: Remove this
187
Nikolas Klauser4c1bf592022-02-11 19:15:18 +0100188// TODO: remove these headers
189#include <__functional/binary_function.h>
190#include <__functional/invoke.h>
191#include <__functional/operations.h>
192#include <__functional/reference_wrapper.h>
193#include <__functional/unary_function.h>
194#include <__functional/weak_result_type.h>
195#include <exception>
196#include <new>
197#include <typeinfo>
198
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000199#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500200# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000201#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202
203_LIBCPP_BEGIN_NAMESPACE_STD
204
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000205#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206
Marshall Clowf50d66f2014-03-03 06:18:11 +0000207
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208// __tuple_leaf
209
Eric Fiselierf7394302015-06-13 07:08:02 +0000210template <size_t _Ip, class _Hp,
211 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000212 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213class __tuple_leaf;
214
215template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500216inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000218 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219{
220 swap(__x.get(), __y.get());
221}
222
223template <size_t _Ip, class _Hp, bool>
224class __tuple_leaf
225{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000226 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000227
Eric Fiselierca8bba12016-07-20 02:57:39 +0000228 template <class _Tp>
229 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000230#if __has_keyword(__reference_binds_to_temporary)
231 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000232#else
233 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000234#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000235 }
236
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500237 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000238 __tuple_leaf& operator=(const __tuple_leaf&);
239public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500240 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000241 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242 {static_assert(!is_reference<_Hp>::value,
243 "Attempted to default construct a reference element in a tuple");}
244
245 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500246 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000248 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249 {static_assert(!is_reference<_Hp>::value,
250 "Attempted to default construct a reference element in a tuple");}
251
252 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500253 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000255 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 {static_assert(!is_reference<_Hp>::value,
257 "Attempted to default construct a reference element in a tuple");}
258
259 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500260 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000262 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263 {static_assert(!is_reference<_Hp>::value,
264 "Attempted to default construct a reference element in a tuple");}
265
Howard Hinnant693fc212010-09-27 17:54:17 +0000266 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400267 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000268 _And<
269 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
270 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000271 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000272 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000273 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000274 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000275 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000276 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000277 {static_assert(__can_bind_reference<_Tp&&>(),
278 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279
280 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500281 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000283 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000284 {static_assert(__can_bind_reference<_Tp&&>(),
285 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286
287 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500288 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000290 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000291 {static_assert(!is_reference<_Hp>::value,
292 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293
294 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500295 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000297 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000298 {static_assert(!is_reference<_Hp>::value,
299 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300
Marshall Clow47fcee52014-04-21 23:48:09 +0000301 __tuple_leaf(const __tuple_leaf& __t) = default;
302 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500304 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000305 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000306 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000307 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000308 return 0;
309 }
310
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000311 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
312 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000313};
314
315template <size_t _Ip, class _Hp>
316class __tuple_leaf<_Ip, _Hp, true>
317 : private _Hp
318{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500319 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320 __tuple_leaf& operator=(const __tuple_leaf&);
321public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500322 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000323 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324
325 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500326 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
328
329 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500330 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000331 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
332 : _Hp(allocator_arg_t(), __a) {}
333
334 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500335 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
337 : _Hp(__a) {}
338
Howard Hinnant693fc212010-09-27 17:54:17 +0000339 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400340 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000341 _And<
342 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
343 is_constructible<_Hp, _Tp>
344 >::value
345 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000346 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000347 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000348 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000349 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350
351 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500352 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000354 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000355
356 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500357 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000359 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360
361 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500362 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000364 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000365
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000366 __tuple_leaf(__tuple_leaf const &) = default;
367 __tuple_leaf(__tuple_leaf &&) = default;
368
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500369 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000370 int
371 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000373 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374 return 0;
375 }
376
Marshall Clow2229cee2013-07-22 16:02:19 +0000377 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
378 _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 +0000379};
380
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000381template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500382_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000383void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384
Marshall Clowc470eae2014-10-15 10:33:02 +0000385template <class _Tp>
386struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000387
Marshall Clowc470eae2014-10-15 10:33:02 +0000388template <class ..._Tp>
389struct __all_default_constructible<__tuple_types<_Tp...>>
390 : __all<is_default_constructible<_Tp>::value...>
391{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000392
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393// __tuple_impl
394
395template<class _Indx, class ..._Tp> struct __tuple_impl;
396
397template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000398struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399 : public __tuple_leaf<_Indx, _Tp>...
400{
Howard Hinnant38469632012-07-06 20:39:45 +0000401 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500402 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000403 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000404
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405 template <size_t ..._Uf, class ..._Tf,
406 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000407 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 explicit
409 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
410 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000411 _Up&&... __u)
412 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
413 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000414 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000415 __tuple_leaf<_Ul, _Tl>()...
416 {}
417
418 template <class _Alloc, size_t ..._Uf, class ..._Tf,
419 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500420 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421 explicit
422 __tuple_impl(allocator_arg_t, const _Alloc& __a,
423 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
424 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
425 _Up&&... __u) :
426 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000427 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
429 {}
430
431 template <class _Tuple,
432 class = typename enable_if
433 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000434 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000435 >::type
436 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000437 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000438 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
439 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000440 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
441 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442 {}
443
444 template <class _Alloc, class _Tuple,
445 class = typename enable_if
446 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000447 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448 >::type
449 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500450 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
452 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000453 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000454 _VSTD::forward<typename tuple_element<_Indx,
455 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456 {}
457
Howard Hinnant0d032d12013-11-06 17:45:43 +0000458 __tuple_impl(const __tuple_impl&) = default;
459 __tuple_impl(__tuple_impl&&) = default;
460
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500461 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000462 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000463 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400465 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466 }
467};
468
Louis Dionne6c0d5342018-07-31 11:56:20 -0400469template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500470_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400471void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
472 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
473}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000474
Louis Dionne6c0d5342018-07-31 11:56:20 -0400475template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500476_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400477void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
478 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500479 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400480 ), void(), 0)...);
481}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000482
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000484class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000486 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000488 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489
Marshall Clow0abb1042013-07-17 18:25:36 +0000490 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000491 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000492 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000493 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000494 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000495 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000496 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
497 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500499 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500
Louis Dionne574e2e32021-02-10 16:19:50 -0500501 // tuple() constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400502 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500503 _And<
504 _IsImpDefault<_Tp>... // explicit check
505 >::value
506 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400507 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000508 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500509 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
510 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000511
Louis Dionne574e2e32021-02-10 16:19:50 -0500512 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400513 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500514 _And<
515 _IsDefault<_Tp>...,
516 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
517 >::value
518 , int> = 0>
519 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
520 explicit tuple()
521 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
522 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000523
Louis Dionne9ce598d2021-09-08 09:14:43 -0400524 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500525 _And<
526 _IsImpDefault<_Tp>... // explicit check
527 >::value
528 , int> = 0>
529 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
530 tuple(allocator_arg_t, _Alloc const& __a)
531 : __base_(allocator_arg_t(), __a,
532 __tuple_indices<>(), __tuple_types<>(),
533 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
534 __tuple_types<_Tp...>()) {}
535
536 template <class _Alloc,
537 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400538 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500539 _And<
540 _IsDefault<_Tp>...,
541 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
542 >::value
543 , int> = 0>
544 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
545 explicit tuple(allocator_arg_t, _Alloc const& __a)
546 : __base_(allocator_arg_t(), __a,
547 __tuple_indices<>(), __tuple_types<>(),
548 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
549 __tuple_types<_Tp...>()) {}
550
551 // tuple(const T&...) constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400552 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500553 _And<
554 _BoolConstant<sizeof...(_Tp) >= 1>,
555 is_copy_constructible<_Tp>...,
556 is_convertible<const _Tp&, _Tp>... // explicit check
557 >::value
558 , int> = 0>
559 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
560 tuple(const _Tp& ... __t)
561 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
562 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
563 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
564 typename __make_tuple_indices<0>::type(),
565 typename __make_tuple_types<tuple, 0>::type(),
566 __t...
567 ) {}
568
Louis Dionne9ce598d2021-09-08 09:14:43 -0400569 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500570 _And<
571 _BoolConstant<sizeof...(_Tp) >= 1>,
572 is_copy_constructible<_Tp>...,
573 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
574 >::value
575 , int> = 0>
576 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
577 explicit tuple(const _Tp& ... __t)
578 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
579 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
580 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
581 typename __make_tuple_indices<0>::type(),
582 typename __make_tuple_types<tuple, 0>::type(),
583 __t...
584 ) {}
585
Louis Dionne9ce598d2021-09-08 09:14:43 -0400586 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500587 _And<
588 _BoolConstant<sizeof...(_Tp) >= 1>,
589 is_copy_constructible<_Tp>...,
590 is_convertible<const _Tp&, _Tp>... // explicit check
591 >::value
592 , int> = 0>
593 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
594 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
595 : __base_(allocator_arg_t(), __a,
596 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
597 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
598 typename __make_tuple_indices<0>::type(),
599 typename __make_tuple_types<tuple, 0>::type(),
600 __t...
601 ) {}
602
Louis Dionne9ce598d2021-09-08 09:14:43 -0400603 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500604 _And<
605 _BoolConstant<sizeof...(_Tp) >= 1>,
606 is_copy_constructible<_Tp>...,
607 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
608 >::value
609 , int> = 0>
610 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
611 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
612 : __base_(allocator_arg_t(), __a,
613 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
614 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
615 typename __make_tuple_indices<0>::type(),
616 typename __make_tuple_types<tuple, 0>::type(),
617 __t...
618 ) {}
619
620 // tuple(U&& ...) constructors (including allocator_arg_t variants)
621 template <class ..._Up> struct _IsThisTuple : false_type { };
622 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
623
624 template <class ..._Up>
625 struct _EnableUTypesCtor : _And<
626 _BoolConstant<sizeof...(_Tp) >= 1>,
627 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
628 is_constructible<_Tp, _Up>...
629 > { };
630
Louis Dionne9ce598d2021-09-08 09:14:43 -0400631 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500632 _And<
633 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
634 _EnableUTypesCtor<_Up...>,
635 is_convertible<_Up, _Tp>... // explicit check
636 >::value
637 , int> = 0>
638 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
639 tuple(_Up&&... __u)
640 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
641 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
642 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
643 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
644 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
645 _VSTD::forward<_Up>(__u)...) {}
646
Louis Dionne9ce598d2021-09-08 09:14:43 -0400647 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500648 _And<
649 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
650 _EnableUTypesCtor<_Up...>,
651 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
652 >::value
653 , int> = 0>
654 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
655 explicit tuple(_Up&&... __u)
656 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
657 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
658 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
659 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
660 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
661 _VSTD::forward<_Up>(__u)...) {}
662
Louis Dionne9ce598d2021-09-08 09:14:43 -0400663 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500664 _And<
665 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
666 _EnableUTypesCtor<_Up...>,
667 is_convertible<_Up, _Tp>... // explicit check
668 >::value
669 , int> = 0>
670 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
671 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
672 : __base_(allocator_arg_t(), __a,
673 typename __make_tuple_indices<sizeof...(_Up)>::type(),
674 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
675 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
676 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
677 _VSTD::forward<_Up>(__u)...) {}
678
Louis Dionne9ce598d2021-09-08 09:14:43 -0400679 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500680 _And<
681 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
682 _EnableUTypesCtor<_Up...>,
683 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
684 >::value
685 , int> = 0>
686 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
687 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
688 : __base_(allocator_arg_t(), __a,
689 typename __make_tuple_indices<sizeof...(_Up)>::type(),
690 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
691 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
692 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
693 _VSTD::forward<_Up>(__u)...) {}
694
695 // Copy and move constructors (including the allocator_arg_t variants)
696 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000697 tuple(tuple&&) = default;
698
Louis Dionne9ce598d2021-09-08 09:14:43 -0400699 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500700 _And<is_copy_constructible<_Tp>...>::value
701 , int> = 0>
702 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
703 : __base_(allocator_arg_t(), __alloc, __t)
704 { }
705
Louis Dionne9ce598d2021-09-08 09:14:43 -0400706 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500707 _And<is_move_constructible<_Tp>...>::value
708 , int> = 0>
709 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
710 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
711 { }
712
713 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
714 template <class ..._Up>
715 struct _EnableCopyFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400716 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
717 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500718 _BoolConstant<sizeof...(_Tp) != 1>,
719 // _Tp and _Up are 1-element packs - the pack expansions look
720 // weird to avoid tripping up the type traits in degenerate cases
721 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500722 _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
723 _Not<is_constructible<_Tp, const tuple<_Up>&> >...
724 >
725 >,
726 is_constructible<_Tp, const _Up&>...
727 > { };
728
Louis Dionne9ce598d2021-09-08 09:14:43 -0400729 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500730 _And<
731 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
732 _EnableCopyFromOtherTuple<_Up...>,
733 is_convertible<const _Up&, _Tp>... // explicit check
734 >::value
735 , int> = 0>
736 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
737 tuple(const tuple<_Up...>& __t)
738 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
739 : __base_(__t)
740 { }
741
Louis Dionne9ce598d2021-09-08 09:14:43 -0400742 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500743 _And<
744 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
745 _EnableCopyFromOtherTuple<_Up...>,
746 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
747 >::value
748 , int> = 0>
749 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
750 explicit tuple(const tuple<_Up...>& __t)
751 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
752 : __base_(__t)
753 { }
754
Louis Dionne9ce598d2021-09-08 09:14:43 -0400755 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500756 _And<
757 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
758 _EnableCopyFromOtherTuple<_Up...>,
759 is_convertible<const _Up&, _Tp>... // explicit check
760 >::value
761 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500762 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500763 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
764 : __base_(allocator_arg_t(), __a, __t)
765 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000766
Louis Dionne9ce598d2021-09-08 09:14:43 -0400767 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500768 _And<
769 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
770 _EnableCopyFromOtherTuple<_Up...>,
771 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
772 >::value
773 , int> = 0>
774 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
775 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
776 : __base_(allocator_arg_t(), __a, __t)
777 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000778
Louis Dionne574e2e32021-02-10 16:19:50 -0500779 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
780 template <class ..._Up>
781 struct _EnableMoveFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400782 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
783 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500784 _BoolConstant<sizeof...(_Tp) != 1>,
785 // _Tp and _Up are 1-element packs - the pack expansions look
786 // weird to avoid tripping up the type traits in degenerate cases
787 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500788 _Not<is_convertible<tuple<_Up>, _Tp> >...,
789 _Not<is_constructible<_Tp, tuple<_Up> > >...
790 >
791 >,
792 is_constructible<_Tp, _Up>...
793 > { };
794
Louis Dionne9ce598d2021-09-08 09:14:43 -0400795 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500796 _And<
797 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
798 _EnableMoveFromOtherTuple<_Up...>,
799 is_convertible<_Up, _Tp>... // explicit check
800 >::value
801 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000802 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500803 tuple(tuple<_Up...>&& __t)
804 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
805 : __base_(_VSTD::move(__t))
806 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000807
Louis Dionne9ce598d2021-09-08 09:14:43 -0400808 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500809 _And<
810 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
811 _EnableMoveFromOtherTuple<_Up...>,
812 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
813 >::value
814 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000815 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500816 explicit tuple(tuple<_Up...>&& __t)
817 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
818 : __base_(_VSTD::move(__t))
819 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000820
Louis Dionne9ce598d2021-09-08 09:14:43 -0400821 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500822 _And<
823 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
824 _EnableMoveFromOtherTuple<_Up...>,
825 is_convertible<_Up, _Tp>... // explicit check
826 >::value
827 , int> = 0>
828 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
829 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
830 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
831 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832
Louis Dionne9ce598d2021-09-08 09:14:43 -0400833 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500834 _And<
835 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
836 _EnableMoveFromOtherTuple<_Up...>,
837 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
838 >::value
839 , int> = 0>
840 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
841 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
842 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
843 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000844
Louis Dionne574e2e32021-02-10 16:19:50 -0500845 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
846 template <class _Up1, class _Up2, class ..._DependentTp>
847 struct _EnableImplicitCopyFromPair : _And<
848 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
849 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
850 is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
851 is_convertible<const _Up2&, _SecondType<_DependentTp...> >
852 > { };
Howard Hinnant65704d02012-04-01 23:10:42 +0000853
Louis Dionne574e2e32021-02-10 16:19:50 -0500854 template <class _Up1, class _Up2, class ..._DependentTp>
855 struct _EnableExplicitCopyFromPair : _And<
856 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
857 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
858 _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
859 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
860 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861
Louis Dionne9ce598d2021-09-08 09:14:43 -0400862 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500863 _And<
864 _BoolConstant<sizeof...(_Tp) == 2>,
865 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
866 >::value
867 , int> = 0>
868 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
869 tuple(const pair<_Up1, _Up2>& __p)
870 _NOEXCEPT_((_And<
871 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
872 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
873 >::value))
874 : __base_(__p)
875 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876
Louis Dionne9ce598d2021-09-08 09:14:43 -0400877 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500878 _And<
879 _BoolConstant<sizeof...(_Tp) == 2>,
880 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
881 >::value
882 , int> = 0>
883 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
884 explicit tuple(const pair<_Up1, _Up2>& __p)
885 _NOEXCEPT_((_And<
886 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
887 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
888 >::value))
889 : __base_(__p)
890 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000891
Louis Dionne9ce598d2021-09-08 09:14:43 -0400892 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500893 _And<
894 _BoolConstant<sizeof...(_Tp) == 2>,
895 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
896 >::value
897 , int> = 0>
898 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
899 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
900 : __base_(allocator_arg_t(), __a, __p)
901 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902
Louis Dionne9ce598d2021-09-08 09:14:43 -0400903 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500904 _And<
905 _BoolConstant<sizeof...(_Tp) == 2>,
906 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
907 >::value
908 , int> = 0>
909 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
910 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
911 : __base_(allocator_arg_t(), __a, __p)
912 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000913
Louis Dionne574e2e32021-02-10 16:19:50 -0500914 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
915 template <class _Up1, class _Up2, class ..._DependentTp>
916 struct _EnableImplicitMoveFromPair : _And<
917 is_constructible<_FirstType<_DependentTp...>, _Up1>,
918 is_constructible<_SecondType<_DependentTp...>, _Up2>,
919 is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
920 is_convertible<_Up2, _SecondType<_DependentTp...> >
921 > { };
Eric Fiselierec5a2102019-07-12 23:01:48 +0000922
Louis Dionne574e2e32021-02-10 16:19:50 -0500923 template <class _Up1, class _Up2, class ..._DependentTp>
924 struct _EnableExplicitMoveFromPair : _And<
925 is_constructible<_FirstType<_DependentTp...>, _Up1>,
926 is_constructible<_SecondType<_DependentTp...>, _Up2>,
927 _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
928 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
929 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000930
Louis Dionne9ce598d2021-09-08 09:14:43 -0400931 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500932 _And<
933 _BoolConstant<sizeof...(_Tp) == 2>,
934 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
935 >::value
936 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400937 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500938 tuple(pair<_Up1, _Up2>&& __p)
939 _NOEXCEPT_((_And<
940 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
941 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
942 >::value))
943 : __base_(_VSTD::move(__p))
944 { }
945
Louis Dionne9ce598d2021-09-08 09:14:43 -0400946 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500947 _And<
948 _BoolConstant<sizeof...(_Tp) == 2>,
949 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
950 >::value
951 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400952 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500953 explicit tuple(pair<_Up1, _Up2>&& __p)
954 _NOEXCEPT_((_And<
955 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
956 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
957 >::value))
958 : __base_(_VSTD::move(__p))
959 { }
960
Louis Dionne9ce598d2021-09-08 09:14:43 -0400961 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500962 _And<
963 _BoolConstant<sizeof...(_Tp) == 2>,
964 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
965 >::value
966 , int> = 0>
967 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
968 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
969 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
970 { }
971
Louis Dionne9ce598d2021-09-08 09:14:43 -0400972 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500973 _And<
974 _BoolConstant<sizeof...(_Tp) == 2>,
975 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
976 >::value
977 , int> = 0>
978 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
979 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
980 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
981 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000982
Louis Dionne6c0d5342018-07-31 11:56:20 -0400983 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500984 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400985 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
986 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000987 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400988 _VSTD::__memberwise_copy_assign(*this, __tuple,
989 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000990 return *this;
991 }
992
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500993 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400994 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
995 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000996 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400997 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
998 __tuple_types<_Tp...>(),
999 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +00001000 return *this;
1001 }
1002
Louis Dionne9ce598d2021-09-08 09:14:43 -04001003 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001004 _And<
1005 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1006 is_assignable<_Tp&, _Up const&>...
1007 >::value
1008 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001009 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001010 tuple& operator=(tuple<_Up...> const& __tuple)
1011 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1012 {
1013 _VSTD::__memberwise_copy_assign(*this, __tuple,
1014 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1015 return *this;
1016 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017
Louis Dionne9ce598d2021-09-08 09:14:43 -04001018 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001019 _And<
1020 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1021 is_assignable<_Tp&, _Up>...
1022 >::value
1023 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001024 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001025 tuple& operator=(tuple<_Up...>&& __tuple)
1026 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1027 {
1028 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1029 __tuple_types<_Up...>(),
1030 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1031 return *this;
1032 }
1033
Louis Dionne9ce598d2021-09-08 09:14:43 -04001034 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001035 _And<_Dep,
1036 _BoolConstant<sizeof...(_Tp) == 2>,
1037 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1038 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1039 >::value
1040 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001041 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001042 tuple& operator=(pair<_Up1, _Up2> const& __pair)
1043 _NOEXCEPT_((_And<
1044 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1045 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1046 >::value))
1047 {
1048 _VSTD::get<0>(*this) = __pair.first;
1049 _VSTD::get<1>(*this) = __pair.second;
1050 return *this;
1051 }
1052
Louis Dionne9ce598d2021-09-08 09:14:43 -04001053 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001054 _And<_Dep,
1055 _BoolConstant<sizeof...(_Tp) == 2>,
1056 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1057 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1058 >::value
1059 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001060 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001061 tuple& operator=(pair<_Up1, _Up2>&& __pair)
1062 _NOEXCEPT_((_And<
1063 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1064 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1065 >::value))
1066 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001067 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1068 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001069 return *this;
1070 }
1071
1072 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001073 template<class _Up, size_t _Np, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001074 _And<
1075 _BoolConstant<_Np == sizeof...(_Tp)>,
1076 is_assignable<_Tp&, _Up const&>...
1077 >::value
1078 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001079 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001080 tuple& operator=(array<_Up, _Np> const& __array)
1081 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1082 {
1083 _VSTD::__memberwise_copy_assign(*this, __array,
1084 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1085 return *this;
1086 }
1087
1088 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001089 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001090 _And<
1091 _BoolConstant<_Np == sizeof...(_Tp)>,
1092 is_assignable<_Tp&, _Up>...
1093 >::value
1094 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001095 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001096 tuple& operator=(array<_Up, _Np>&& __array)
1097 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1098 {
1099 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1100 __tuple_types<_If<true, _Up, _Tp>...>(),
1101 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1102 return *this;
1103 }
1104
1105 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001106 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001107 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001108 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109};
1110
1111template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001112class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001113{
1114public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001115 _LIBCPP_INLINE_VISIBILITY constexpr
1116 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001117 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001118 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001119 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001120 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001121 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001122 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001123 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001124 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001125 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001126 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001127 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001128 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001129 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001130 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001131};
1132
Joe Loserd9b3d972022-03-12 10:46:57 -05001133#if _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001134template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1135 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1136struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1137 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1138};
1139
1140template <class... _TTypes, class... _UTypes>
1141 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1142struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1143 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1144};
Joe Loserd9b3d972022-03-12 10:46:57 -05001145#endif // _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001146
1147#if _LIBCPP_STD_VER > 14
Louis Dionne616da2a2019-08-12 18:30:31 +00001148template <class ..._Tp>
1149tuple(_Tp...) -> tuple<_Tp...>;
1150template <class _Tp1, class _Tp2>
1151tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1152template <class _Alloc, class ..._Tp>
1153tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1154template <class _Alloc, class _Tp1, class _Tp2>
1155tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1156template <class _Alloc, class ..._Tp>
1157tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001158#endif
1159
Howard Hinnantc51e1022010-05-11 19:42:16 +00001160template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001161inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001162typename enable_if
1163<
1164 __all<__is_swappable<_Tp>::value...>::value,
1165 void
1166>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001167swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1168 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1169 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170
1171// get
1172
1173template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001174inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001175typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001176get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001177{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001178 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001179 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180}
1181
1182template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001183inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001184const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001185get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001187 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001188 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001189}
1190
Howard Hinnant22e97242010-11-17 19:52:17 +00001191template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001192inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001193typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001194get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001195{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001196 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001197 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001198 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001199}
1200
Eric Fiselier6dea8092015-12-18 00:36:55 +00001201template <size_t _Ip, class ..._Tp>
1202inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1203const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1204get(const tuple<_Tp...>&& __t) _NOEXCEPT
1205{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001206 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001207 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001208 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001209}
1210
Marshall Clow15b02e02013-07-13 02:54:05 +00001211#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001212
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001213namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001214
Louis Dionne7dd28aa2021-07-20 11:46:05 -04001215static constexpr size_t __not_found = static_cast<size_t>(-1);
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001216static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001217
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001218inline _LIBCPP_INLINE_VISIBILITY
1219constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1220 return !__matches ? __res :
1221 (__res == __not_found ? __curr_i : __ambiguous);
1222}
Marshall Clow15b02e02013-07-13 02:54:05 +00001223
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001224template <size_t _Nx>
1225inline _LIBCPP_INLINE_VISIBILITY
1226constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1227 return __i == _Nx ? __not_found :
1228 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1229}
1230
1231template <class _T1, class ..._Args>
1232struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001233 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001234 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001235 static_assert(value != __not_found, "type not found in type list" );
1236 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001237};
1238
Eric Fiselier8087d302016-07-02 03:46:08 +00001239template <class _T1>
1240struct __find_exactly_one_checked<_T1> {
1241 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1242};
1243
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001244} // namespace __find_detail
Marshall Clow15b02e02013-07-13 02:54:05 +00001245
1246template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001247struct __find_exactly_one_t
1248 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1249};
Marshall Clow15b02e02013-07-13 02:54:05 +00001250
1251template <class _T1, class... _Args>
1252inline _LIBCPP_INLINE_VISIBILITY
1253constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1254{
1255 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1256}
1257
1258template <class _T1, class... _Args>
1259inline _LIBCPP_INLINE_VISIBILITY
1260constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1261{
1262 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1263}
1264
1265template <class _T1, class... _Args>
1266inline _LIBCPP_INLINE_VISIBILITY
1267constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1268{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001269 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001270}
1271
Eric Fiselier6dea8092015-12-18 00:36:55 +00001272template <class _T1, class... _Args>
1273inline _LIBCPP_INLINE_VISIBILITY
1274constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1275{
1276 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1277}
1278
Marshall Clow15b02e02013-07-13 02:54:05 +00001279#endif
1280
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281// tie
1282
1283template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001284inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001286tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287{
1288 return tuple<_Tp&...>(__t...);
1289}
1290
1291template <class _Up>
1292struct __ignore_t
1293{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001295 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1296 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297};
1298
Eric Fiselier24e70262017-02-06 01:25:31 +00001299namespace {
Louis Dionne559be102021-09-22 09:35:32 -04001300 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001301} // namespace
Howard Hinnantc51e1022010-05-11 19:42:16 +00001302
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001304inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001305tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001306make_tuple(_Tp&&... __t)
1307{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001308 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001309}
1310
Howard Hinnant3d203a32010-08-19 18:59:38 +00001311template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001312inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1313tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001314forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001315{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001316 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001317}
1318
Howard Hinnantc834c512011-11-29 18:15:50 +00001319template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001320struct __tuple_equal
1321{
1322 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001323 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324 bool operator()(const _Tp& __x, const _Up& __y)
1325 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001326 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001327 }
1328};
1329
1330template <>
1331struct __tuple_equal<0>
1332{
1333 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001334 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001335 bool operator()(const _Tp&, const _Up&)
1336 {
1337 return true;
1338 }
1339};
1340
1341template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001342inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001343bool
1344operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1345{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001346 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001347 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1348}
1349
Joe Loserd9b3d972022-03-12 10:46:57 -05001350#if _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001351
1352// operator<=>
1353
1354template <class ..._Tp, class ..._Up, size_t ..._Is>
1355_LIBCPP_HIDE_FROM_ABI constexpr
1356auto
1357__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1358 common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1359 static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1360 return __result;
1361}
1362
1363template <class ..._Tp, class ..._Up>
1364requires (sizeof...(_Tp) == sizeof...(_Up))
1365_LIBCPP_HIDE_FROM_ABI constexpr
1366common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1367operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1368{
1369 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1370}
1371
Joe Loserd9b3d972022-03-12 10:46:57 -05001372#else // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001373
Howard Hinnantc51e1022010-05-11 19:42:16 +00001374template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001375inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376bool
1377operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1378{
1379 return !(__x == __y);
1380}
1381
Howard Hinnantc834c512011-11-29 18:15:50 +00001382template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001383struct __tuple_less
1384{
1385 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001386 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387 bool operator()(const _Tp& __x, const _Up& __y)
1388 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001389 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1390 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1391 return true;
1392 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1393 return false;
1394 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395 }
1396};
1397
1398template <>
1399struct __tuple_less<0>
1400{
1401 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001402 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001403 bool operator()(const _Tp&, const _Up&)
1404 {
1405 return false;
1406 }
1407};
1408
1409template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001410inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411bool
1412operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1413{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001414 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1416}
1417
1418template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001419inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001420bool
1421operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1422{
1423 return __y < __x;
1424}
1425
1426template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001427inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428bool
1429operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1430{
1431 return !(__x < __y);
1432}
1433
1434template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001435inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001436bool
1437operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1438{
1439 return !(__y < __x);
1440}
1441
Joe Loserd9b3d972022-03-12 10:46:57 -05001442#endif // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001443
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444// tuple_cat
1445
Howard Hinnant6256ee72010-12-11 20:47:50 +00001446template <class _Tp, class _Up> struct __tuple_cat_type;
1447
1448template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001449struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001451 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001452};
1453
1454template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1455struct __tuple_cat_return_1
1456{
1457};
1458
1459template <class ..._Types, class _Tuple0>
1460struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1461{
Nikolas Klauser669b4452022-02-17 22:53:20 +01001462 using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
1463 tuple<_Types...>,
1464 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
1465 >::type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001466};
1467
1468template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1469struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1470 : public __tuple_cat_return_1<
1471 typename __tuple_cat_type<
1472 tuple<_Types...>,
Nikolas Klauser669b4452022-02-17 22:53:20 +01001473 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001474 >::type,
1475 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1476 _Tuple1, _Tuples...>
1477{
1478};
1479
1480template <class ..._Tuples> struct __tuple_cat_return;
1481
1482template <class _Tuple0, class ..._Tuples>
1483struct __tuple_cat_return<_Tuple0, _Tuples...>
1484 : public __tuple_cat_return_1<tuple<>,
1485 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1486 _Tuples...>
1487{
1488};
1489
1490template <>
1491struct __tuple_cat_return<>
1492{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001493 typedef _LIBCPP_NODEBUG tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001494};
1495
Marshall Clow2229cee2013-07-22 16:02:19 +00001496inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001497tuple<>
1498tuple_cat()
1499{
1500 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501}
1502
Howard Hinnantc834c512011-11-29 18:15:50 +00001503template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001504struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001505
Howard Hinnant21376f62010-12-12 23:04:37 +00001506template <class ..._Types, size_t ..._I0, class _Tuple0>
1507struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001509 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001510 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1511 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1512};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001513
Howard Hinnant21376f62010-12-12 23:04:37 +00001514template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1515struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1516 _Tuple0, _Tuple1, _Tuples...>
1517 : public __tuple_cat_return_ref_imp<
1518 tuple<_Types..., typename __apply_cv<_Tuple0,
1519 typename tuple_element<_I0,
1520 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1521 typename __make_tuple_indices<tuple_size<typename
1522 remove_reference<_Tuple1>::type>::value>::type,
1523 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524{
Howard Hinnant21376f62010-12-12 23:04:37 +00001525};
1526
1527template <class _Tuple0, class ..._Tuples>
1528struct __tuple_cat_return_ref
1529 : public __tuple_cat_return_ref_imp<tuple<>,
1530 typename __make_tuple_indices<
1531 tuple_size<typename remove_reference<_Tuple0>::type>::value
1532 >::type, _Tuple0, _Tuples...>
1533{
1534};
1535
1536template <class _Types, class _I0, class _J0>
1537struct __tuple_cat;
1538
1539template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001540struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001541{
1542 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001543 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001544 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1545 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1546 {
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 Dionnea6c4ace2021-08-31 10:32:11 -04001557 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1558 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001559 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001560 tuple<_Types...,
1561 typename __apply_cv<_Tuple0, typename tuple_element<
1562 _J0, _T0>::type>::type&&...>,
1563 typename __make_tuple_indices<sizeof...(_Types) +
1564 tuple_size<_T0>::value>::type,
1565 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1566 _VSTD::forward_as_tuple(
1567 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1568 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1569 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001570 }
1571};
1572
1573template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001574inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001575typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1576tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1577{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001578 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001579 return __tuple_cat<tuple<>, __tuple_indices<>,
1580 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001581 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1582 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001583}
1584
1585template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001586struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587 : true_type {};
1588
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589template <class _T1, class _T2>
1590template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001591inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592pair<_T1, _T2>::pair(piecewise_construct_t,
1593 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1594 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001595 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1596 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001597{
1598}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001599
Eric Fiselier8e892c52016-07-18 00:35:56 +00001600#if _LIBCPP_STD_VER > 14
1601template <class _Tp>
Louis Dionne559be102021-09-22 09:35:32 -04001602inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001603
1604#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1605
1606template <class _Fn, class _Tuple, size_t ..._Id>
1607inline _LIBCPP_INLINE_VISIBILITY
1608constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1609 __tuple_indices<_Id...>)
1610_LIBCPP_NOEXCEPT_RETURN(
1611 _VSTD::__invoke_constexpr(
1612 _VSTD::forward<_Fn>(__f),
1613 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1614)
1615
1616template <class _Fn, class _Tuple>
1617inline _LIBCPP_INLINE_VISIBILITY
1618constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1619_LIBCPP_NOEXCEPT_RETURN(
1620 _VSTD::__apply_tuple_impl(
1621 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001622 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001623)
1624
1625template <class _Tp, class _Tuple, size_t... _Idx>
1626inline _LIBCPP_INLINE_VISIBILITY
1627constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1628_LIBCPP_NOEXCEPT_RETURN(
1629 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1630)
1631
1632template <class _Tp, class _Tuple>
1633inline _LIBCPP_INLINE_VISIBILITY
1634constexpr _Tp make_from_tuple(_Tuple&& __t)
1635_LIBCPP_NOEXCEPT_RETURN(
1636 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001637 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001638)
1639
1640#undef _LIBCPP_NOEXCEPT_RETURN
1641
1642#endif // _LIBCPP_STD_VER > 14
1643
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001644#endif // !defined(_LIBCPP_CXX03_LANG)
1645
Howard Hinnantc51e1022010-05-11 19:42:16 +00001646_LIBCPP_END_NAMESPACE_STD
1647
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001648#endif // _LIBCPP_TUPLE