blob: 251b685912b61ace571cb8539e69cc770b9cb198 [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>
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 Klausera0e0edb2022-06-16 22:43:46 +0200186// standard-mandated includes
187#include <compare>
188
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000189#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500190# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000191#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192
193_LIBCPP_BEGIN_NAMESPACE_STD
194
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000195#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196
Marshall Clowf50d66f2014-03-03 06:18:11 +0000197
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198// __tuple_leaf
199
Eric Fiselierf7394302015-06-13 07:08:02 +0000200template <size_t _Ip, class _Hp,
201 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000202 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203class __tuple_leaf;
204
205template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500206inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000208 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000209{
210 swap(__x.get(), __y.get());
211}
212
213template <size_t _Ip, class _Hp, bool>
214class __tuple_leaf
215{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000216 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217
Eric Fiselierca8bba12016-07-20 02:57:39 +0000218 template <class _Tp>
219 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000220#if __has_keyword(__reference_binds_to_temporary)
221 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000222#else
223 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000224#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000225 }
226
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500227 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228 __tuple_leaf& operator=(const __tuple_leaf&);
229public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500230 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000231 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000232 {static_assert(!is_reference<_Hp>::value,
233 "Attempted to default construct a reference element in a tuple");}
234
235 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500236 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000238 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239 {static_assert(!is_reference<_Hp>::value,
240 "Attempted to default construct a reference element in a tuple");}
241
242 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500243 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000244 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000245 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246 {static_assert(!is_reference<_Hp>::value,
247 "Attempted to default construct a reference element in a tuple");}
248
249 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500250 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000252 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 {static_assert(!is_reference<_Hp>::value,
254 "Attempted to default construct a reference element in a tuple");}
255
Howard Hinnant693fc212010-09-27 17:54:17 +0000256 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400257 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000258 _And<
259 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
260 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000261 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000262 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000263 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000264 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000265 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000266 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000267 {static_assert(__can_bind_reference<_Tp&&>(),
268 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000269
270 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500271 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000273 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000274 {static_assert(__can_bind_reference<_Tp&&>(),
275 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276
277 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500278 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000280 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000281 {static_assert(!is_reference<_Hp>::value,
282 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000283
284 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500285 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000287 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000288 {static_assert(!is_reference<_Hp>::value,
289 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290
Marshall Clow47fcee52014-04-21 23:48:09 +0000291 __tuple_leaf(const __tuple_leaf& __t) = default;
292 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500294 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000295 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000297 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000298 return 0;
299 }
300
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000301 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
302 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303};
304
305template <size_t _Ip, class _Hp>
306class __tuple_leaf<_Ip, _Hp, true>
307 : private _Hp
308{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500309 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000310 __tuple_leaf& operator=(const __tuple_leaf&);
311public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500312 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000313 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314
315 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500316 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
318
319 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500320 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000321 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
322 : _Hp(allocator_arg_t(), __a) {}
323
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, 2>, const _Alloc& __a)
327 : _Hp(__a) {}
328
Howard Hinnant693fc212010-09-27 17:54:17 +0000329 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400330 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000331 _And<
332 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
333 is_constructible<_Hp, _Tp>
334 >::value
335 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000336 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000337 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000338 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000339 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340
341 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500342 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000343 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000344 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345
346 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500347 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000349 : _Hp(allocator_arg_t(), __a, _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, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000354 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000355
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000356 __tuple_leaf(__tuple_leaf const &) = default;
357 __tuple_leaf(__tuple_leaf &&) = default;
358
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500359 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000360 int
361 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000363 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364 return 0;
365 }
366
Marshall Clow2229cee2013-07-22 16:02:19 +0000367 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
368 _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 +0000369};
370
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000371template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500372_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000373void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374
Marshall Clowc470eae2014-10-15 10:33:02 +0000375template <class _Tp>
376struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000377
Marshall Clowc470eae2014-10-15 10:33:02 +0000378template <class ..._Tp>
379struct __all_default_constructible<__tuple_types<_Tp...>>
380 : __all<is_default_constructible<_Tp>::value...>
381{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000382
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383// __tuple_impl
384
385template<class _Indx, class ..._Tp> struct __tuple_impl;
386
387template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000388struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389 : public __tuple_leaf<_Indx, _Tp>...
390{
Howard Hinnant38469632012-07-06 20:39:45 +0000391 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500392 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000393 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000394
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 template <size_t ..._Uf, class ..._Tf,
396 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000397 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398 explicit
399 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
400 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000401 _Up&&... __u)
402 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
403 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000404 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405 __tuple_leaf<_Ul, _Tl>()...
406 {}
407
408 template <class _Alloc, size_t ..._Uf, class ..._Tf,
409 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500410 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 explicit
412 __tuple_impl(allocator_arg_t, const _Alloc& __a,
413 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
414 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
415 _Up&&... __u) :
416 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000417 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000418 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
419 {}
420
421 template <class _Tuple,
422 class = typename enable_if
423 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000424 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 >::type
426 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000427 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000428 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
429 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000430 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
431 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432 {}
433
434 template <class _Alloc, class _Tuple,
435 class = typename enable_if
436 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000437 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438 >::type
439 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500440 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
442 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000443 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000444 _VSTD::forward<typename tuple_element<_Indx,
445 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446 {}
447
Howard Hinnant0d032d12013-11-06 17:45:43 +0000448 __tuple_impl(const __tuple_impl&) = default;
449 __tuple_impl(__tuple_impl&&) = default;
450
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500451 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000453 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000454 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400455 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456 }
457};
458
Louis Dionne6c0d5342018-07-31 11:56:20 -0400459template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500460_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400461void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
462 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
463}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000464
Louis Dionne6c0d5342018-07-31 11:56:20 -0400465template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500466_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400467void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
468 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500469 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400470 ), void(), 0)...);
471}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000472
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000474class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000476 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000477
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000478 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000479
Marshall Clow0abb1042013-07-17 18:25:36 +0000480 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000481 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000482 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000483 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000484 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000485 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000486 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
487 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500489 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490
Louis Dionne574e2e32021-02-10 16:19:50 -0500491 // tuple() constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400492 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500493 _And<
494 _IsImpDefault<_Tp>... // explicit check
495 >::value
496 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400497 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000498 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500499 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
500 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000501
Louis Dionne574e2e32021-02-10 16:19:50 -0500502 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400503 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500504 _And<
505 _IsDefault<_Tp>...,
506 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
507 >::value
508 , int> = 0>
509 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
510 explicit tuple()
511 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
512 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000513
Louis Dionne9ce598d2021-09-08 09:14:43 -0400514 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500515 _And<
516 _IsImpDefault<_Tp>... // explicit check
517 >::value
518 , int> = 0>
519 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
520 tuple(allocator_arg_t, _Alloc const& __a)
521 : __base_(allocator_arg_t(), __a,
522 __tuple_indices<>(), __tuple_types<>(),
523 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
524 __tuple_types<_Tp...>()) {}
525
526 template <class _Alloc,
527 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400528 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500529 _And<
530 _IsDefault<_Tp>...,
531 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
532 >::value
533 , int> = 0>
534 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
535 explicit tuple(allocator_arg_t, _Alloc const& __a)
536 : __base_(allocator_arg_t(), __a,
537 __tuple_indices<>(), __tuple_types<>(),
538 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
539 __tuple_types<_Tp...>()) {}
540
541 // tuple(const T&...) constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400542 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500543 _And<
544 _BoolConstant<sizeof...(_Tp) >= 1>,
545 is_copy_constructible<_Tp>...,
546 is_convertible<const _Tp&, _Tp>... // explicit check
547 >::value
548 , int> = 0>
549 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
550 tuple(const _Tp& ... __t)
551 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
552 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
553 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
554 typename __make_tuple_indices<0>::type(),
555 typename __make_tuple_types<tuple, 0>::type(),
556 __t...
557 ) {}
558
Louis Dionne9ce598d2021-09-08 09:14:43 -0400559 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500560 _And<
561 _BoolConstant<sizeof...(_Tp) >= 1>,
562 is_copy_constructible<_Tp>...,
563 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
564 >::value
565 , int> = 0>
566 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
567 explicit tuple(const _Tp& ... __t)
568 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
569 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
570 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
571 typename __make_tuple_indices<0>::type(),
572 typename __make_tuple_types<tuple, 0>::type(),
573 __t...
574 ) {}
575
Louis Dionne9ce598d2021-09-08 09:14:43 -0400576 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500577 _And<
578 _BoolConstant<sizeof...(_Tp) >= 1>,
579 is_copy_constructible<_Tp>...,
580 is_convertible<const _Tp&, _Tp>... // explicit check
581 >::value
582 , int> = 0>
583 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
584 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
585 : __base_(allocator_arg_t(), __a,
586 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
587 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
588 typename __make_tuple_indices<0>::type(),
589 typename __make_tuple_types<tuple, 0>::type(),
590 __t...
591 ) {}
592
Louis Dionne9ce598d2021-09-08 09:14:43 -0400593 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500594 _And<
595 _BoolConstant<sizeof...(_Tp) >= 1>,
596 is_copy_constructible<_Tp>...,
597 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
598 >::value
599 , int> = 0>
600 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
601 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
602 : __base_(allocator_arg_t(), __a,
603 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
604 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
605 typename __make_tuple_indices<0>::type(),
606 typename __make_tuple_types<tuple, 0>::type(),
607 __t...
608 ) {}
609
610 // tuple(U&& ...) constructors (including allocator_arg_t variants)
611 template <class ..._Up> struct _IsThisTuple : false_type { };
612 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
613
614 template <class ..._Up>
615 struct _EnableUTypesCtor : _And<
616 _BoolConstant<sizeof...(_Tp) >= 1>,
617 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
618 is_constructible<_Tp, _Up>...
619 > { };
620
Louis Dionne9ce598d2021-09-08 09:14:43 -0400621 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500622 _And<
623 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
624 _EnableUTypesCtor<_Up...>,
625 is_convertible<_Up, _Tp>... // explicit check
626 >::value
627 , int> = 0>
628 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
629 tuple(_Up&&... __u)
630 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
631 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
632 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
633 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
634 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
635 _VSTD::forward<_Up>(__u)...) {}
636
Louis Dionne9ce598d2021-09-08 09:14:43 -0400637 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500638 _And<
639 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
640 _EnableUTypesCtor<_Up...>,
641 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
642 >::value
643 , int> = 0>
644 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
645 explicit tuple(_Up&&... __u)
646 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
647 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
648 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
649 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
650 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
651 _VSTD::forward<_Up>(__u)...) {}
652
Louis Dionne9ce598d2021-09-08 09:14:43 -0400653 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500654 _And<
655 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
656 _EnableUTypesCtor<_Up...>,
657 is_convertible<_Up, _Tp>... // explicit check
658 >::value
659 , int> = 0>
660 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
661 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
662 : __base_(allocator_arg_t(), __a,
663 typename __make_tuple_indices<sizeof...(_Up)>::type(),
664 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
665 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
666 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
667 _VSTD::forward<_Up>(__u)...) {}
668
Louis Dionne9ce598d2021-09-08 09:14:43 -0400669 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500670 _And<
671 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
672 _EnableUTypesCtor<_Up...>,
673 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
674 >::value
675 , int> = 0>
676 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
677 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
678 : __base_(allocator_arg_t(), __a,
679 typename __make_tuple_indices<sizeof...(_Up)>::type(),
680 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
681 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
682 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
683 _VSTD::forward<_Up>(__u)...) {}
684
685 // Copy and move constructors (including the allocator_arg_t variants)
686 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000687 tuple(tuple&&) = default;
688
Louis Dionne9ce598d2021-09-08 09:14:43 -0400689 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500690 _And<is_copy_constructible<_Tp>...>::value
691 , int> = 0>
692 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
693 : __base_(allocator_arg_t(), __alloc, __t)
694 { }
695
Louis Dionne9ce598d2021-09-08 09:14:43 -0400696 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500697 _And<is_move_constructible<_Tp>...>::value
698 , int> = 0>
699 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
700 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
701 { }
702
703 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
704 template <class ..._Up>
705 struct _EnableCopyFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400706 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
707 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500708 _BoolConstant<sizeof...(_Tp) != 1>,
709 // _Tp and _Up are 1-element packs - the pack expansions look
710 // weird to avoid tripping up the type traits in degenerate cases
711 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500712 _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
713 _Not<is_constructible<_Tp, const tuple<_Up>&> >...
714 >
715 >,
716 is_constructible<_Tp, const _Up&>...
717 > { };
718
Louis Dionne9ce598d2021-09-08 09:14:43 -0400719 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500720 _And<
721 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
722 _EnableCopyFromOtherTuple<_Up...>,
723 is_convertible<const _Up&, _Tp>... // explicit check
724 >::value
725 , int> = 0>
726 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
727 tuple(const tuple<_Up...>& __t)
728 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
729 : __base_(__t)
730 { }
731
Louis Dionne9ce598d2021-09-08 09:14:43 -0400732 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500733 _And<
734 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
735 _EnableCopyFromOtherTuple<_Up...>,
736 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
737 >::value
738 , int> = 0>
739 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
740 explicit tuple(const tuple<_Up...>& __t)
741 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
742 : __base_(__t)
743 { }
744
Louis Dionne9ce598d2021-09-08 09:14:43 -0400745 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500746 _And<
747 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
748 _EnableCopyFromOtherTuple<_Up...>,
749 is_convertible<const _Up&, _Tp>... // explicit check
750 >::value
751 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500752 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500753 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
754 : __base_(allocator_arg_t(), __a, __t)
755 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000756
Louis Dionne9ce598d2021-09-08 09:14:43 -0400757 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500758 _And<
759 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
760 _EnableCopyFromOtherTuple<_Up...>,
761 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
762 >::value
763 , int> = 0>
764 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
765 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
766 : __base_(allocator_arg_t(), __a, __t)
767 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000768
Louis Dionne574e2e32021-02-10 16:19:50 -0500769 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
770 template <class ..._Up>
771 struct _EnableMoveFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400772 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
773 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500774 _BoolConstant<sizeof...(_Tp) != 1>,
775 // _Tp and _Up are 1-element packs - the pack expansions look
776 // weird to avoid tripping up the type traits in degenerate cases
777 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500778 _Not<is_convertible<tuple<_Up>, _Tp> >...,
779 _Not<is_constructible<_Tp, tuple<_Up> > >...
780 >
781 >,
782 is_constructible<_Tp, _Up>...
783 > { };
784
Louis Dionne9ce598d2021-09-08 09:14:43 -0400785 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500786 _And<
787 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
788 _EnableMoveFromOtherTuple<_Up...>,
789 is_convertible<_Up, _Tp>... // explicit check
790 >::value
791 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000792 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500793 tuple(tuple<_Up...>&& __t)
794 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
795 : __base_(_VSTD::move(__t))
796 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797
Louis Dionne9ce598d2021-09-08 09:14:43 -0400798 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500799 _And<
800 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
801 _EnableMoveFromOtherTuple<_Up...>,
802 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
803 >::value
804 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000805 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500806 explicit tuple(tuple<_Up...>&& __t)
807 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
808 : __base_(_VSTD::move(__t))
809 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000810
Louis Dionne9ce598d2021-09-08 09:14:43 -0400811 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500812 _And<
813 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
814 _EnableMoveFromOtherTuple<_Up...>,
815 is_convertible<_Up, _Tp>... // explicit check
816 >::value
817 , int> = 0>
818 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
819 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
820 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
821 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822
Louis Dionne9ce598d2021-09-08 09:14:43 -0400823 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500824 _And<
825 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
826 _EnableMoveFromOtherTuple<_Up...>,
827 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
828 >::value
829 , int> = 0>
830 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
831 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
832 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
833 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000834
Louis Dionne574e2e32021-02-10 16:19:50 -0500835 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
836 template <class _Up1, class _Up2, class ..._DependentTp>
837 struct _EnableImplicitCopyFromPair : _And<
838 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
839 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
840 is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
841 is_convertible<const _Up2&, _SecondType<_DependentTp...> >
842 > { };
Howard Hinnant65704d02012-04-01 23:10:42 +0000843
Louis Dionne574e2e32021-02-10 16:19:50 -0500844 template <class _Up1, class _Up2, class ..._DependentTp>
845 struct _EnableExplicitCopyFromPair : _And<
846 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
847 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
848 _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
849 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
850 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851
Louis Dionne9ce598d2021-09-08 09:14:43 -0400852 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500853 _And<
854 _BoolConstant<sizeof...(_Tp) == 2>,
855 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
856 >::value
857 , int> = 0>
858 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
859 tuple(const pair<_Up1, _Up2>& __p)
860 _NOEXCEPT_((_And<
861 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
862 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
863 >::value))
864 : __base_(__p)
865 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866
Louis Dionne9ce598d2021-09-08 09:14:43 -0400867 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500868 _And<
869 _BoolConstant<sizeof...(_Tp) == 2>,
870 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
871 >::value
872 , int> = 0>
873 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
874 explicit tuple(const pair<_Up1, _Up2>& __p)
875 _NOEXCEPT_((_And<
876 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
877 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
878 >::value))
879 : __base_(__p)
880 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000881
Louis Dionne9ce598d2021-09-08 09:14:43 -0400882 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500883 _And<
884 _BoolConstant<sizeof...(_Tp) == 2>,
885 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
886 >::value
887 , int> = 0>
888 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
889 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
890 : __base_(allocator_arg_t(), __a, __p)
891 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892
Louis Dionne9ce598d2021-09-08 09:14:43 -0400893 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500894 _And<
895 _BoolConstant<sizeof...(_Tp) == 2>,
896 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
897 >::value
898 , int> = 0>
899 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
900 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
901 : __base_(allocator_arg_t(), __a, __p)
902 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000903
Louis Dionne574e2e32021-02-10 16:19:50 -0500904 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
905 template <class _Up1, class _Up2, class ..._DependentTp>
906 struct _EnableImplicitMoveFromPair : _And<
907 is_constructible<_FirstType<_DependentTp...>, _Up1>,
908 is_constructible<_SecondType<_DependentTp...>, _Up2>,
909 is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
910 is_convertible<_Up2, _SecondType<_DependentTp...> >
911 > { };
Eric Fiselierec5a2102019-07-12 23:01:48 +0000912
Louis Dionne574e2e32021-02-10 16:19:50 -0500913 template <class _Up1, class _Up2, class ..._DependentTp>
914 struct _EnableExplicitMoveFromPair : _And<
915 is_constructible<_FirstType<_DependentTp...>, _Up1>,
916 is_constructible<_SecondType<_DependentTp...>, _Up2>,
917 _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
918 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
919 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920
Louis Dionne9ce598d2021-09-08 09:14:43 -0400921 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500922 _And<
923 _BoolConstant<sizeof...(_Tp) == 2>,
924 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
925 >::value
926 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400927 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500928 tuple(pair<_Up1, _Up2>&& __p)
929 _NOEXCEPT_((_And<
930 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
931 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
932 >::value))
933 : __base_(_VSTD::move(__p))
934 { }
935
Louis Dionne9ce598d2021-09-08 09:14:43 -0400936 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500937 _And<
938 _BoolConstant<sizeof...(_Tp) == 2>,
939 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
940 >::value
941 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400942 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500943 explicit tuple(pair<_Up1, _Up2>&& __p)
944 _NOEXCEPT_((_And<
945 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
946 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
947 >::value))
948 : __base_(_VSTD::move(__p))
949 { }
950
Louis Dionne9ce598d2021-09-08 09:14:43 -0400951 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500952 _And<
953 _BoolConstant<sizeof...(_Tp) == 2>,
954 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
955 >::value
956 , int> = 0>
957 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
958 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
959 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
960 { }
961
Louis Dionne9ce598d2021-09-08 09:14:43 -0400962 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500963 _And<
964 _BoolConstant<sizeof...(_Tp) == 2>,
965 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
966 >::value
967 , int> = 0>
968 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
969 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
970 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
971 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000972
Louis Dionne6c0d5342018-07-31 11:56:20 -0400973 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500974 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400975 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
976 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000977 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400978 _VSTD::__memberwise_copy_assign(*this, __tuple,
979 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000980 return *this;
981 }
982
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_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
985 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000986 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400987 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
988 __tuple_types<_Tp...>(),
989 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000990 return *this;
991 }
992
Louis Dionne9ce598d2021-09-08 09:14:43 -0400993 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -0400994 _And<
995 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
996 is_assignable<_Tp&, _Up const&>...
997 >::value
998 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500999 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001000 tuple& operator=(tuple<_Up...> const& __tuple)
1001 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1002 {
1003 _VSTD::__memberwise_copy_assign(*this, __tuple,
1004 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1005 return *this;
1006 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007
Louis Dionne9ce598d2021-09-08 09:14:43 -04001008 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001009 _And<
1010 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1011 is_assignable<_Tp&, _Up>...
1012 >::value
1013 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001014 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001015 tuple& operator=(tuple<_Up...>&& __tuple)
1016 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1017 {
1018 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1019 __tuple_types<_Up...>(),
1020 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1021 return *this;
1022 }
1023
Louis Dionne9ce598d2021-09-08 09:14:43 -04001024 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001025 _And<_Dep,
1026 _BoolConstant<sizeof...(_Tp) == 2>,
1027 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1028 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1029 >::value
1030 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001031 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001032 tuple& operator=(pair<_Up1, _Up2> const& __pair)
1033 _NOEXCEPT_((_And<
1034 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1035 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1036 >::value))
1037 {
1038 _VSTD::get<0>(*this) = __pair.first;
1039 _VSTD::get<1>(*this) = __pair.second;
1040 return *this;
1041 }
1042
Louis Dionne9ce598d2021-09-08 09:14:43 -04001043 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001044 _And<_Dep,
1045 _BoolConstant<sizeof...(_Tp) == 2>,
1046 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1047 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1048 >::value
1049 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001050 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001051 tuple& operator=(pair<_Up1, _Up2>&& __pair)
1052 _NOEXCEPT_((_And<
1053 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1054 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1055 >::value))
1056 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001057 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1058 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001059 return *this;
1060 }
1061
1062 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001063 template<class _Up, size_t _Np, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001064 _And<
1065 _BoolConstant<_Np == sizeof...(_Tp)>,
1066 is_assignable<_Tp&, _Up const&>...
1067 >::value
1068 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001069 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001070 tuple& operator=(array<_Up, _Np> const& __array)
1071 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1072 {
1073 _VSTD::__memberwise_copy_assign(*this, __array,
1074 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1075 return *this;
1076 }
1077
1078 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001079 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001080 _And<
1081 _BoolConstant<_Np == sizeof...(_Tp)>,
1082 is_assignable<_Tp&, _Up>...
1083 >::value
1084 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001085 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001086 tuple& operator=(array<_Up, _Np>&& __array)
1087 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1088 {
1089 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1090 __tuple_types<_If<true, _Up, _Tp>...>(),
1091 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1092 return *this;
1093 }
1094
1095 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001096 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001097 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001098 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099};
1100
1101template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001102class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103{
1104public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001105 _LIBCPP_INLINE_VISIBILITY constexpr
1106 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001107 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001108 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001109 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001110 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001111 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001112 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001113 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001114 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001115 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001116 template <class _Alloc, class _Up>
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&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001119 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001120 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001121};
1122
Joe Loserd9b3d972022-03-12 10:46:57 -05001123#if _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001124template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1125 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1126struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1127 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1128};
1129
1130template <class... _TTypes, class... _UTypes>
1131 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1132struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1133 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1134};
Joe Loserd9b3d972022-03-12 10:46:57 -05001135#endif // _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001136
1137#if _LIBCPP_STD_VER > 14
Louis Dionne616da2a2019-08-12 18:30:31 +00001138template <class ..._Tp>
1139tuple(_Tp...) -> tuple<_Tp...>;
1140template <class _Tp1, class _Tp2>
1141tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1142template <class _Alloc, class ..._Tp>
1143tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1144template <class _Alloc, class _Tp1, class _Tp2>
1145tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1146template <class _Alloc, class ..._Tp>
1147tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001148#endif
1149
Howard Hinnantc51e1022010-05-11 19:42:16 +00001150template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001151inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001152typename enable_if
1153<
1154 __all<__is_swappable<_Tp>::value...>::value,
1155 void
1156>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001157swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1158 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1159 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001160
1161// get
1162
1163template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001164inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001165typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001166get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001168 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001169 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170}
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 +00001174const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001175get(const 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<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179}
1180
Howard Hinnant22e97242010-11-17 19:52:17 +00001181template <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 +00001183typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001184get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001185{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001186 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001187 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001188 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001189}
1190
Eric Fiselier6dea8092015-12-18 00:36:55 +00001191template <size_t _Ip, class ..._Tp>
1192inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1193const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1194get(const tuple<_Tp...>&& __t) _NOEXCEPT
1195{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001196 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001197 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001198 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001199}
1200
Marshall Clow15b02e02013-07-13 02:54:05 +00001201#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001202
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001203namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001204
Louis Dionne7dd28aa2021-07-20 11:46:05 -04001205static constexpr size_t __not_found = static_cast<size_t>(-1);
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001206static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001207
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001208inline _LIBCPP_INLINE_VISIBILITY
1209constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1210 return !__matches ? __res :
1211 (__res == __not_found ? __curr_i : __ambiguous);
1212}
Marshall Clow15b02e02013-07-13 02:54:05 +00001213
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001214template <size_t _Nx>
1215inline _LIBCPP_INLINE_VISIBILITY
1216constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1217 return __i == _Nx ? __not_found :
1218 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1219}
1220
1221template <class _T1, class ..._Args>
1222struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001223 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001224 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001225 static_assert(value != __not_found, "type not found in type list" );
1226 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001227};
1228
Eric Fiselier8087d302016-07-02 03:46:08 +00001229template <class _T1>
1230struct __find_exactly_one_checked<_T1> {
1231 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1232};
1233
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001234} // namespace __find_detail
Marshall Clow15b02e02013-07-13 02:54:05 +00001235
1236template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001237struct __find_exactly_one_t
1238 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1239};
Marshall Clow15b02e02013-07-13 02:54:05 +00001240
1241template <class _T1, class... _Args>
1242inline _LIBCPP_INLINE_VISIBILITY
1243constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1244{
1245 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1246}
1247
1248template <class _T1, class... _Args>
1249inline _LIBCPP_INLINE_VISIBILITY
1250constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1251{
1252 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1253}
1254
1255template <class _T1, class... _Args>
1256inline _LIBCPP_INLINE_VISIBILITY
1257constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1258{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001259 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001260}
1261
Eric Fiselier6dea8092015-12-18 00:36:55 +00001262template <class _T1, class... _Args>
1263inline _LIBCPP_INLINE_VISIBILITY
1264constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1265{
1266 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1267}
1268
Marshall Clow15b02e02013-07-13 02:54:05 +00001269#endif
1270
Howard Hinnantc51e1022010-05-11 19:42:16 +00001271// tie
1272
1273template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001274inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001276tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277{
1278 return tuple<_Tp&...>(__t...);
1279}
1280
1281template <class _Up>
1282struct __ignore_t
1283{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001284 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001285 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1286 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287};
1288
Eric Fiselier24e70262017-02-06 01:25:31 +00001289namespace {
Louis Dionne559be102021-09-22 09:35:32 -04001290 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001291} // namespace
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001294inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001295tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296make_tuple(_Tp&&... __t)
1297{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001298 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001299}
1300
Howard Hinnant3d203a32010-08-19 18:59:38 +00001301template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001302inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1303tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001304forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001305{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001306 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001307}
1308
Howard Hinnantc834c512011-11-29 18:15:50 +00001309template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310struct __tuple_equal
1311{
1312 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001313 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314 bool operator()(const _Tp& __x, const _Up& __y)
1315 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001316 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001317 }
1318};
1319
1320template <>
1321struct __tuple_equal<0>
1322{
1323 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001324 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001325 bool operator()(const _Tp&, const _Up&)
1326 {
1327 return true;
1328 }
1329};
1330
1331template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001332inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001333bool
1334operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1335{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001336 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1338}
1339
Joe Loserd9b3d972022-03-12 10:46:57 -05001340#if _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001341
1342// operator<=>
1343
1344template <class ..._Tp, class ..._Up, size_t ..._Is>
1345_LIBCPP_HIDE_FROM_ABI constexpr
1346auto
1347__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1348 common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1349 static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1350 return __result;
1351}
1352
1353template <class ..._Tp, class ..._Up>
1354requires (sizeof...(_Tp) == sizeof...(_Up))
1355_LIBCPP_HIDE_FROM_ABI constexpr
1356common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1357operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1358{
1359 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1360}
1361
Joe Loserd9b3d972022-03-12 10:46:57 -05001362#else // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001363
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001365inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001366bool
1367operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1368{
1369 return !(__x == __y);
1370}
1371
Howard Hinnantc834c512011-11-29 18:15:50 +00001372template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373struct __tuple_less
1374{
1375 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001376 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001377 bool operator()(const _Tp& __x, const _Up& __y)
1378 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001379 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1380 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1381 return true;
1382 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1383 return false;
1384 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001385 }
1386};
1387
1388template <>
1389struct __tuple_less<0>
1390{
1391 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001392 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393 bool operator()(const _Tp&, const _Up&)
1394 {
1395 return false;
1396 }
1397};
1398
1399template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001400inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001401bool
1402operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1403{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001404 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001405 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
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{
1413 return __y < __x;
1414}
1415
1416template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001417inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001418bool
1419operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1420{
1421 return !(__x < __y);
1422}
1423
1424template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001425inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426bool
1427operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1428{
1429 return !(__y < __x);
1430}
1431
Joe Loserd9b3d972022-03-12 10:46:57 -05001432#endif // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001433
Howard Hinnantc51e1022010-05-11 19:42:16 +00001434// tuple_cat
1435
Howard Hinnant6256ee72010-12-11 20:47:50 +00001436template <class _Tp, class _Up> struct __tuple_cat_type;
1437
1438template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001439struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001441 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001442};
1443
1444template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1445struct __tuple_cat_return_1
1446{
1447};
1448
1449template <class ..._Types, class _Tuple0>
1450struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1451{
Nikolas Klauser669b4452022-02-17 22:53:20 +01001452 using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
1453 tuple<_Types...>,
1454 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
1455 >::type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001456};
1457
1458template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1459struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1460 : public __tuple_cat_return_1<
1461 typename __tuple_cat_type<
1462 tuple<_Types...>,
Nikolas Klauser669b4452022-02-17 22:53:20 +01001463 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001464 >::type,
1465 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1466 _Tuple1, _Tuples...>
1467{
1468};
1469
1470template <class ..._Tuples> struct __tuple_cat_return;
1471
1472template <class _Tuple0, class ..._Tuples>
1473struct __tuple_cat_return<_Tuple0, _Tuples...>
1474 : public __tuple_cat_return_1<tuple<>,
1475 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1476 _Tuples...>
1477{
1478};
1479
1480template <>
1481struct __tuple_cat_return<>
1482{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001483 typedef _LIBCPP_NODEBUG tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001484};
1485
Marshall Clow2229cee2013-07-22 16:02:19 +00001486inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001487tuple<>
1488tuple_cat()
1489{
1490 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001491}
1492
Howard Hinnantc834c512011-11-29 18:15:50 +00001493template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001494struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001495
Howard Hinnant21376f62010-12-12 23:04:37 +00001496template <class ..._Types, size_t ..._I0, class _Tuple0>
1497struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001499 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001500 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1501 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1502};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001503
Howard Hinnant21376f62010-12-12 23:04:37 +00001504template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1505struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1506 _Tuple0, _Tuple1, _Tuples...>
1507 : public __tuple_cat_return_ref_imp<
1508 tuple<_Types..., typename __apply_cv<_Tuple0,
1509 typename tuple_element<_I0,
1510 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1511 typename __make_tuple_indices<tuple_size<typename
1512 remove_reference<_Tuple1>::type>::value>::type,
1513 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514{
Howard Hinnant21376f62010-12-12 23:04:37 +00001515};
1516
1517template <class _Tuple0, class ..._Tuples>
1518struct __tuple_cat_return_ref
1519 : public __tuple_cat_return_ref_imp<tuple<>,
1520 typename __make_tuple_indices<
1521 tuple_size<typename remove_reference<_Tuple0>::type>::value
1522 >::type, _Tuple0, _Tuples...>
1523{
1524};
1525
1526template <class _Types, class _I0, class _J0>
1527struct __tuple_cat;
1528
1529template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001530struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001531{
1532 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001533 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001534 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1535 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1536 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001537 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
David Blaikie699a5e22019-10-28 18:03:59 -07001538 return _VSTD::forward_as_tuple(
1539 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1540 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001541 }
1542
1543 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001544 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001545 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1546 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1547 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001548 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001549 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1550 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001551 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001552 tuple<_Types...,
1553 typename __apply_cv<_Tuple0, typename tuple_element<
1554 _J0, _T0>::type>::type&&...>,
1555 typename __make_tuple_indices<sizeof...(_Types) +
1556 tuple_size<_T0>::value>::type,
1557 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1558 _VSTD::forward_as_tuple(
1559 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1560 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1561 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001562 }
1563};
1564
1565template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001566inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001567typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1568tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1569{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001570 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001571 return __tuple_cat<tuple<>, __tuple_indices<>,
1572 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001573 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1574 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001575}
1576
1577template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001578struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001579 : true_type {};
1580
Howard Hinnantc51e1022010-05-11 19:42:16 +00001581template <class _T1, class _T2>
1582template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001583inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584pair<_T1, _T2>::pair(piecewise_construct_t,
1585 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1586 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001587 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1588 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589{
1590}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001591
Eric Fiselier8e892c52016-07-18 00:35:56 +00001592#if _LIBCPP_STD_VER > 14
1593template <class _Tp>
Louis Dionne559be102021-09-22 09:35:32 -04001594inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001595
1596#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1597
1598template <class _Fn, class _Tuple, size_t ..._Id>
1599inline _LIBCPP_INLINE_VISIBILITY
1600constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1601 __tuple_indices<_Id...>)
1602_LIBCPP_NOEXCEPT_RETURN(
Nikolas Klausera28f48e2022-04-06 23:10:21 +02001603 _VSTD::__invoke(
Eric Fiselier8e892c52016-07-18 00:35:56 +00001604 _VSTD::forward<_Fn>(__f),
1605 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1606)
1607
1608template <class _Fn, class _Tuple>
1609inline _LIBCPP_INLINE_VISIBILITY
1610constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1611_LIBCPP_NOEXCEPT_RETURN(
1612 _VSTD::__apply_tuple_impl(
1613 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001614 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001615)
1616
1617template <class _Tp, class _Tuple, size_t... _Idx>
1618inline _LIBCPP_INLINE_VISIBILITY
1619constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1620_LIBCPP_NOEXCEPT_RETURN(
1621 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1622)
1623
1624template <class _Tp, class _Tuple>
1625inline _LIBCPP_INLINE_VISIBILITY
1626constexpr _Tp make_from_tuple(_Tuple&& __t)
1627_LIBCPP_NOEXCEPT_RETURN(
1628 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001629 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001630)
1631
1632#undef _LIBCPP_NOEXCEPT_RETURN
1633
1634#endif // _LIBCPP_STD_VER > 14
1635
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001636#endif // !defined(_LIBCPP_CXX03_LANG)
1637
Howard Hinnantc51e1022010-05-11 19:42:16 +00001638_LIBCPP_END_NAMESPACE_STD
1639
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001640#endif // _LIBCPP_TUPLE