blob: 8c5b24e7ad6ce1639cafd9ee825d7339a03854f9 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
Chandler Carruth7642bb12019-01-19 08:50:56 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TUPLE
11#define _LIBCPP_TUPLE
12
13/*
14 tuple synopsis
15
16namespace std
17{
18
19template <class... T>
20class tuple {
21public:
Louis Dionnea7a2beb2019-09-26 14:51:10 +000022 explicit(see-below) constexpr tuple();
Louis Dionne1afad1d2019-07-22 20:45:23 +000023 explicit(see-below) tuple(const T&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000024 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000025 explicit(see-below) tuple(U&&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000026 tuple(const tuple&) = default;
Howard Hinnant89ef1212011-05-27 19:08:18 +000027 tuple(tuple&&) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +000028 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000029 explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000030 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000031 explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000033 explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000034 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000035 explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000036
37 // allocator-extended constructors
38 template <class Alloc>
39 tuple(allocator_arg_t, const Alloc& a);
40 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050041 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050043 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000044 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050045 tuple(allocator_arg_t, const Alloc& a, const tuple&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000046 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050047 tuple(allocator_arg_t, const Alloc& a, tuple&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000048 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050049 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000050 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050051 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000052 template <class Alloc, class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050053 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000054 template <class Alloc, class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050055 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050057 tuple& operator=(const tuple&); // constexpr in C++20
58 tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000059 template <class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050060 tuple& operator=(const tuple<U...>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000061 template <class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050062 tuple& operator=(tuple<U...>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000063 template <class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050064 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000065 template <class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050066 tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000067
Louis Dionne6c0d5342018-07-31 11:56:20 -040068 template<class U, size_t N>
69 tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
70 template<class U, size_t N>
71 tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
72
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050073 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000074};
75
Nikolas Klauserad26ba52022-01-17 19:45:42 +010076
77template<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23
78 requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }
79struct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {
80 using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
81};
82
83template<class... TTypes, class... UTypes> // since C++23
84 requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }
85struct common_type<tuple<TTypes...>, tuple<UTypes...>> {
86 using type = tuple<common_type_t<TTypes, UTypes>...>;
87};
88
Louis Dionne616da2a2019-08-12 18:30:31 +000089template <class ...T>
90tuple(T...) -> tuple<T...>; // since C++17
91template <class T1, class T2>
92tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
93template <class Alloc, class ...T>
94tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
95template <class Alloc, class T1, class T2>
96tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
97template <class Alloc, class ...T>
98tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
99
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000100inline constexpr unspecified ignore;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000101
Marshall Clow2229cee2013-07-22 16:02:19 +0000102template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clowded420b2013-10-05 18:46:37 +0000103template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clowa8892812014-02-25 16:11:46 +0000104template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clow2229cee2013-07-22 16:02:19 +0000105template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier8e892c52016-07-18 00:35:56 +0000106
107// [tuple.apply], calling a function with a tuple of arguments:
108template <class F, class Tuple>
109 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
110template <class T, class Tuple>
111 constexpr T make_from_tuple(Tuple&& t); // C++17
112
Howard Hinnantc51e1022010-05-11 19:42:16 +0000113// 20.4.1.4, tuple helper classes:
Marshall Clowce62b4d2019-01-11 21:57:12 +0000114template <class T> struct tuple_size; // undefined
115template <class... T> struct tuple_size<tuple<T...>>;
Eric Fiselier8e892c52016-07-18 00:35:56 +0000116template <class T>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000117 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Louis Dionnee684aa62019-04-01 16:39:34 +0000118template <size_t I, class T> struct tuple_element; // undefined
119template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
Marshall Clow36907512015-11-19 19:45:29 +0000120template <size_t I, class T>
121 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000122
123// 20.4.1.5, element access:
Marshall Clow36907512015-11-19 19:45:29 +0000124template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000125 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000126 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000127template <size_t I, class... T>
128 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000129 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000130template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000131 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow0abb1042013-07-17 18:25:36 +0000132 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000133template <size_t I, class... T>
134 const typename tuple_element<I, tuple<T...>>::type&&
135 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136
Marshall Clow15b02e02013-07-13 02:54:05 +0000137template <class T1, class... T>
138 constexpr T1& get(tuple<T...>&) noexcept; // C++14
139template <class T1, class... T>
Marshall Clow36907512015-11-19 19:45:29 +0000140 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000141template <class T1, class... T>
142 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000143template <class T1, class... T>
144 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000145
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146// 20.4.1.6, relational operators:
Marshall Clow2229cee2013-07-22 16:02:19 +0000147template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Kent Ross0861b0d2021-10-08 14:54:28 -0700148template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
149template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
150template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
151template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
152template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
153template<class... T, class... U>
154 constexpr common_comparison_category_t<synth-three-way-result<T, U>...>
155 operator<=>(const tuple<T...>&, const tuple<U...>&); // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156
157template <class... Types, class Alloc>
158 struct uses_allocator<tuple<Types...>, Alloc>;
159
160template <class... Types>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000161 void
162 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164} // std
165
166*/
167
Louis Dionneb4fce352022-03-25 12:55:36 -0400168#include <__assert> // all public C++ headers provide the assertion handler
Kent Ross0861b0d2021-10-08 14:54:28 -0700169#include <__compare/common_comparison_category.h>
170#include <__compare/synth_three_way.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000171#include <__config>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000172#include <__functional/unwrap_ref.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400173#include <__memory/allocator_arg_t.h>
174#include <__memory/uses_allocator.h>
175#include <__tuple>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000176#include <__utility/forward.h>
Kent Ross0861b0d2021-10-08 14:54:28 -0700177#include <__utility/integer_sequence.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000178#include <__utility/move.h>
Nikolas Klauser8fccd622022-03-05 19:17:07 +0100179#include <__utility/pair.h>
180#include <__utility/piecewise_construct.h>
181#include <__utility/swap.h>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400182#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000183#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000185#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000187#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500188# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000189#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190
191_LIBCPP_BEGIN_NAMESPACE_STD
192
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000193#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194
Marshall Clowf50d66f2014-03-03 06:18:11 +0000195
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196// __tuple_leaf
197
Eric Fiselierf7394302015-06-13 07:08:02 +0000198template <size_t _Ip, class _Hp,
199 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000200 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201class __tuple_leaf;
202
203template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500204inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000206 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207{
208 swap(__x.get(), __y.get());
209}
210
211template <size_t _Ip, class _Hp, bool>
212class __tuple_leaf
213{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000214 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215
Eric Fiselierca8bba12016-07-20 02:57:39 +0000216 template <class _Tp>
217 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000218#if __has_keyword(__reference_binds_to_temporary)
219 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000220#else
221 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000222#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000223 }
224
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500225 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226 __tuple_leaf& operator=(const __tuple_leaf&);
227public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500228 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000229 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000230 {static_assert(!is_reference<_Hp>::value,
231 "Attempted to default construct a reference element in a tuple");}
232
233 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500234 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000236 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237 {static_assert(!is_reference<_Hp>::value,
238 "Attempted to default construct a reference element in a tuple");}
239
240 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500241 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000243 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000244 {static_assert(!is_reference<_Hp>::value,
245 "Attempted to default construct a reference element in a tuple");}
246
247 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500248 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000250 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251 {static_assert(!is_reference<_Hp>::value,
252 "Attempted to default construct a reference element in a tuple");}
253
Howard Hinnant693fc212010-09-27 17:54:17 +0000254 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400255 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000256 _And<
257 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
258 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000259 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000260 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000261 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000262 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000263 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000264 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000265 {static_assert(__can_bind_reference<_Tp&&>(),
266 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000267
268 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500269 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000271 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000272 {static_assert(__can_bind_reference<_Tp&&>(),
273 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000274
275 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500276 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000277 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000278 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000279 {static_assert(!is_reference<_Hp>::value,
280 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281
282 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500283 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000285 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000286 {static_assert(!is_reference<_Hp>::value,
287 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288
Marshall Clow47fcee52014-04-21 23:48:09 +0000289 __tuple_leaf(const __tuple_leaf& __t) = default;
290 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500292 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000293 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000295 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296 return 0;
297 }
298
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000299 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
300 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301};
302
303template <size_t _Ip, class _Hp>
304class __tuple_leaf<_Ip, _Hp, true>
305 : private _Hp
306{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500307 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000308 __tuple_leaf& operator=(const __tuple_leaf&);
309public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500310 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000311 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312
313 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500314 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
316
317 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500318 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000319 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
320 : _Hp(allocator_arg_t(), __a) {}
321
322 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500323 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
325 : _Hp(__a) {}
326
Howard Hinnant693fc212010-09-27 17:54:17 +0000327 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400328 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000329 _And<
330 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
331 is_constructible<_Hp, _Tp>
332 >::value
333 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000334 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000335 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000336 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000337 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338
339 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500340 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000342 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000343
344 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500345 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000347 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348
349 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500350 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000352 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000354 __tuple_leaf(__tuple_leaf const &) = default;
355 __tuple_leaf(__tuple_leaf &&) = default;
356
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500357 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000358 int
359 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000361 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362 return 0;
363 }
364
Marshall Clow2229cee2013-07-22 16:02:19 +0000365 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
366 _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 +0000367};
368
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000369template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500370_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000371void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372
Marshall Clowc470eae2014-10-15 10:33:02 +0000373template <class _Tp>
374struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000375
Marshall Clowc470eae2014-10-15 10:33:02 +0000376template <class ..._Tp>
377struct __all_default_constructible<__tuple_types<_Tp...>>
378 : __all<is_default_constructible<_Tp>::value...>
379{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000380
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381// __tuple_impl
382
383template<class _Indx, class ..._Tp> struct __tuple_impl;
384
385template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000386struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000387 : public __tuple_leaf<_Indx, _Tp>...
388{
Howard Hinnant38469632012-07-06 20:39:45 +0000389 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500390 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000391 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000392
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393 template <size_t ..._Uf, class ..._Tf,
394 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000395 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396 explicit
397 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
398 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000399 _Up&&... __u)
400 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
401 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000402 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403 __tuple_leaf<_Ul, _Tl>()...
404 {}
405
406 template <class _Alloc, size_t ..._Uf, class ..._Tf,
407 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500408 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 explicit
410 __tuple_impl(allocator_arg_t, const _Alloc& __a,
411 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
412 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
413 _Up&&... __u) :
414 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000415 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
417 {}
418
419 template <class _Tuple,
420 class = typename enable_if
421 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000422 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 >::type
424 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000425 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000426 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
427 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000428 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
429 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430 {}
431
432 template <class _Alloc, class _Tuple,
433 class = typename enable_if
434 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000435 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436 >::type
437 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500438 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
440 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000441 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000442 _VSTD::forward<typename tuple_element<_Indx,
443 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444 {}
445
Howard Hinnant0d032d12013-11-06 17:45:43 +0000446 __tuple_impl(const __tuple_impl&) = default;
447 __tuple_impl(__tuple_impl&&) = default;
448
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500449 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000451 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400453 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000454 }
455};
456
Louis Dionne6c0d5342018-07-31 11:56:20 -0400457template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500458_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400459void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
460 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
461}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000462
Louis Dionne6c0d5342018-07-31 11:56:20 -0400463template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500464_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400465void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
466 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500467 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400468 ), void(), 0)...);
469}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000470
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000472class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000474 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000476 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000477
Marshall Clow0abb1042013-07-17 18:25:36 +0000478 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000479 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
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 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const 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 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000484 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
485 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500487 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488
Louis Dionne574e2e32021-02-10 16:19:50 -0500489 // tuple() constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400490 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500491 _And<
492 _IsImpDefault<_Tp>... // explicit check
493 >::value
494 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400495 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000496 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500497 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
498 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000499
Louis Dionne574e2e32021-02-10 16:19:50 -0500500 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400501 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500502 _And<
503 _IsDefault<_Tp>...,
504 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
505 >::value
506 , int> = 0>
507 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
508 explicit tuple()
509 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
510 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000511
Louis Dionne9ce598d2021-09-08 09:14:43 -0400512 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500513 _And<
514 _IsImpDefault<_Tp>... // explicit check
515 >::value
516 , int> = 0>
517 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
518 tuple(allocator_arg_t, _Alloc const& __a)
519 : __base_(allocator_arg_t(), __a,
520 __tuple_indices<>(), __tuple_types<>(),
521 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
522 __tuple_types<_Tp...>()) {}
523
524 template <class _Alloc,
525 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400526 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500527 _And<
528 _IsDefault<_Tp>...,
529 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
530 >::value
531 , int> = 0>
532 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
533 explicit tuple(allocator_arg_t, _Alloc const& __a)
534 : __base_(allocator_arg_t(), __a,
535 __tuple_indices<>(), __tuple_types<>(),
536 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
537 __tuple_types<_Tp...>()) {}
538
539 // tuple(const T&...) constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400540 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500541 _And<
542 _BoolConstant<sizeof...(_Tp) >= 1>,
543 is_copy_constructible<_Tp>...,
544 is_convertible<const _Tp&, _Tp>... // explicit check
545 >::value
546 , int> = 0>
547 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
548 tuple(const _Tp& ... __t)
549 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
550 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
551 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
552 typename __make_tuple_indices<0>::type(),
553 typename __make_tuple_types<tuple, 0>::type(),
554 __t...
555 ) {}
556
Louis Dionne9ce598d2021-09-08 09:14:43 -0400557 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500558 _And<
559 _BoolConstant<sizeof...(_Tp) >= 1>,
560 is_copy_constructible<_Tp>...,
561 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
562 >::value
563 , int> = 0>
564 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
565 explicit tuple(const _Tp& ... __t)
566 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
567 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
568 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
569 typename __make_tuple_indices<0>::type(),
570 typename __make_tuple_types<tuple, 0>::type(),
571 __t...
572 ) {}
573
Louis Dionne9ce598d2021-09-08 09:14:43 -0400574 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500575 _And<
576 _BoolConstant<sizeof...(_Tp) >= 1>,
577 is_copy_constructible<_Tp>...,
578 is_convertible<const _Tp&, _Tp>... // explicit check
579 >::value
580 , int> = 0>
581 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
582 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
583 : __base_(allocator_arg_t(), __a,
584 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
585 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
586 typename __make_tuple_indices<0>::type(),
587 typename __make_tuple_types<tuple, 0>::type(),
588 __t...
589 ) {}
590
Louis Dionne9ce598d2021-09-08 09:14:43 -0400591 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500592 _And<
593 _BoolConstant<sizeof...(_Tp) >= 1>,
594 is_copy_constructible<_Tp>...,
595 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
596 >::value
597 , int> = 0>
598 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
599 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
600 : __base_(allocator_arg_t(), __a,
601 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
602 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
603 typename __make_tuple_indices<0>::type(),
604 typename __make_tuple_types<tuple, 0>::type(),
605 __t...
606 ) {}
607
608 // tuple(U&& ...) constructors (including allocator_arg_t variants)
609 template <class ..._Up> struct _IsThisTuple : false_type { };
610 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
611
612 template <class ..._Up>
613 struct _EnableUTypesCtor : _And<
614 _BoolConstant<sizeof...(_Tp) >= 1>,
615 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
616 is_constructible<_Tp, _Up>...
617 > { };
618
Louis Dionne9ce598d2021-09-08 09:14:43 -0400619 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500620 _And<
621 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
622 _EnableUTypesCtor<_Up...>,
623 is_convertible<_Up, _Tp>... // explicit check
624 >::value
625 , int> = 0>
626 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
627 tuple(_Up&&... __u)
628 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
629 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
630 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
631 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
632 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
633 _VSTD::forward<_Up>(__u)...) {}
634
Louis Dionne9ce598d2021-09-08 09:14:43 -0400635 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500636 _And<
637 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
638 _EnableUTypesCtor<_Up...>,
639 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
640 >::value
641 , int> = 0>
642 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
643 explicit tuple(_Up&&... __u)
644 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
645 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
646 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
647 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
648 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
649 _VSTD::forward<_Up>(__u)...) {}
650
Louis Dionne9ce598d2021-09-08 09:14:43 -0400651 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500652 _And<
653 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
654 _EnableUTypesCtor<_Up...>,
655 is_convertible<_Up, _Tp>... // explicit check
656 >::value
657 , int> = 0>
658 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
659 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
660 : __base_(allocator_arg_t(), __a,
661 typename __make_tuple_indices<sizeof...(_Up)>::type(),
662 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
663 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
664 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
665 _VSTD::forward<_Up>(__u)...) {}
666
Louis Dionne9ce598d2021-09-08 09:14:43 -0400667 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500668 _And<
669 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
670 _EnableUTypesCtor<_Up...>,
671 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
672 >::value
673 , int> = 0>
674 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
675 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
676 : __base_(allocator_arg_t(), __a,
677 typename __make_tuple_indices<sizeof...(_Up)>::type(),
678 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
679 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
680 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
681 _VSTD::forward<_Up>(__u)...) {}
682
683 // Copy and move constructors (including the allocator_arg_t variants)
684 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000685 tuple(tuple&&) = default;
686
Louis Dionne9ce598d2021-09-08 09:14:43 -0400687 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500688 _And<is_copy_constructible<_Tp>...>::value
689 , int> = 0>
690 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
691 : __base_(allocator_arg_t(), __alloc, __t)
692 { }
693
Louis Dionne9ce598d2021-09-08 09:14:43 -0400694 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500695 _And<is_move_constructible<_Tp>...>::value
696 , int> = 0>
697 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
698 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
699 { }
700
701 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
702 template <class ..._Up>
703 struct _EnableCopyFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400704 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
705 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500706 _BoolConstant<sizeof...(_Tp) != 1>,
707 // _Tp and _Up are 1-element packs - the pack expansions look
708 // weird to avoid tripping up the type traits in degenerate cases
709 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500710 _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
711 _Not<is_constructible<_Tp, const tuple<_Up>&> >...
712 >
713 >,
714 is_constructible<_Tp, const _Up&>...
715 > { };
716
Louis Dionne9ce598d2021-09-08 09:14:43 -0400717 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500718 _And<
719 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
720 _EnableCopyFromOtherTuple<_Up...>,
721 is_convertible<const _Up&, _Tp>... // explicit check
722 >::value
723 , int> = 0>
724 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
725 tuple(const tuple<_Up...>& __t)
726 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
727 : __base_(__t)
728 { }
729
Louis Dionne9ce598d2021-09-08 09:14:43 -0400730 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500731 _And<
732 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
733 _EnableCopyFromOtherTuple<_Up...>,
734 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
735 >::value
736 , int> = 0>
737 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
738 explicit tuple(const tuple<_Up...>& __t)
739 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
740 : __base_(__t)
741 { }
742
Louis Dionne9ce598d2021-09-08 09:14:43 -0400743 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500744 _And<
745 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
746 _EnableCopyFromOtherTuple<_Up...>,
747 is_convertible<const _Up&, _Tp>... // explicit check
748 >::value
749 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500750 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500751 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
752 : __base_(allocator_arg_t(), __a, __t)
753 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000754
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 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
760 >::value
761 , int> = 0>
762 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
763 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
764 : __base_(allocator_arg_t(), __a, __t)
765 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000766
Louis Dionne574e2e32021-02-10 16:19:50 -0500767 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
768 template <class ..._Up>
769 struct _EnableMoveFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400770 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
771 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500772 _BoolConstant<sizeof...(_Tp) != 1>,
773 // _Tp and _Up are 1-element packs - the pack expansions look
774 // weird to avoid tripping up the type traits in degenerate cases
775 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500776 _Not<is_convertible<tuple<_Up>, _Tp> >...,
777 _Not<is_constructible<_Tp, tuple<_Up> > >...
778 >
779 >,
780 is_constructible<_Tp, _Up>...
781 > { };
782
Louis Dionne9ce598d2021-09-08 09:14:43 -0400783 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500784 _And<
785 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
786 _EnableMoveFromOtherTuple<_Up...>,
787 is_convertible<_Up, _Tp>... // explicit check
788 >::value
789 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000790 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500791 tuple(tuple<_Up...>&& __t)
792 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
793 : __base_(_VSTD::move(__t))
794 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795
Louis Dionne9ce598d2021-09-08 09:14:43 -0400796 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500797 _And<
798 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
799 _EnableMoveFromOtherTuple<_Up...>,
800 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
801 >::value
802 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000803 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500804 explicit tuple(tuple<_Up...>&& __t)
805 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
806 : __base_(_VSTD::move(__t))
807 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000808
Louis Dionne9ce598d2021-09-08 09:14:43 -0400809 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500810 _And<
811 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
812 _EnableMoveFromOtherTuple<_Up...>,
813 is_convertible<_Up, _Tp>... // explicit check
814 >::value
815 , int> = 0>
816 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
817 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
818 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
819 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +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 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
826 >::value
827 , int> = 0>
828 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
829 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
830 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
831 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000832
Louis Dionne574e2e32021-02-10 16:19:50 -0500833 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
834 template <class _Up1, class _Up2, class ..._DependentTp>
835 struct _EnableImplicitCopyFromPair : _And<
836 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
837 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
838 is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
839 is_convertible<const _Up2&, _SecondType<_DependentTp...> >
840 > { };
Howard Hinnant65704d02012-04-01 23:10:42 +0000841
Louis Dionne574e2e32021-02-10 16:19:50 -0500842 template <class _Up1, class _Up2, class ..._DependentTp>
843 struct _EnableExplicitCopyFromPair : _And<
844 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
845 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
846 _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
847 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
848 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849
Louis Dionne9ce598d2021-09-08 09:14:43 -0400850 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500851 _And<
852 _BoolConstant<sizeof...(_Tp) == 2>,
853 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
854 >::value
855 , int> = 0>
856 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
857 tuple(const pair<_Up1, _Up2>& __p)
858 _NOEXCEPT_((_And<
859 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
860 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
861 >::value))
862 : __base_(__p)
863 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864
Louis Dionne9ce598d2021-09-08 09:14:43 -0400865 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500866 _And<
867 _BoolConstant<sizeof...(_Tp) == 2>,
868 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
869 >::value
870 , int> = 0>
871 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
872 explicit tuple(const pair<_Up1, _Up2>& __p)
873 _NOEXCEPT_((_And<
874 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
875 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
876 >::value))
877 : __base_(__p)
878 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000879
Louis Dionne9ce598d2021-09-08 09:14:43 -0400880 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500881 _And<
882 _BoolConstant<sizeof...(_Tp) == 2>,
883 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
884 >::value
885 , int> = 0>
886 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
887 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
888 : __base_(allocator_arg_t(), __a, __p)
889 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890
Louis Dionne9ce598d2021-09-08 09:14:43 -0400891 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500892 _And<
893 _BoolConstant<sizeof...(_Tp) == 2>,
894 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
895 >::value
896 , int> = 0>
897 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
898 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
899 : __base_(allocator_arg_t(), __a, __p)
900 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000901
Louis Dionne574e2e32021-02-10 16:19:50 -0500902 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
903 template <class _Up1, class _Up2, class ..._DependentTp>
904 struct _EnableImplicitMoveFromPair : _And<
905 is_constructible<_FirstType<_DependentTp...>, _Up1>,
906 is_constructible<_SecondType<_DependentTp...>, _Up2>,
907 is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
908 is_convertible<_Up2, _SecondType<_DependentTp...> >
909 > { };
Eric Fiselierec5a2102019-07-12 23:01:48 +0000910
Louis Dionne574e2e32021-02-10 16:19:50 -0500911 template <class _Up1, class _Up2, class ..._DependentTp>
912 struct _EnableExplicitMoveFromPair : _And<
913 is_constructible<_FirstType<_DependentTp...>, _Up1>,
914 is_constructible<_SecondType<_DependentTp...>, _Up2>,
915 _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
916 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
917 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918
Louis Dionne9ce598d2021-09-08 09:14:43 -0400919 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500920 _And<
921 _BoolConstant<sizeof...(_Tp) == 2>,
922 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
923 >::value
924 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400925 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500926 tuple(pair<_Up1, _Up2>&& __p)
927 _NOEXCEPT_((_And<
928 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
929 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
930 >::value))
931 : __base_(_VSTD::move(__p))
932 { }
933
Louis Dionne9ce598d2021-09-08 09:14:43 -0400934 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500935 _And<
936 _BoolConstant<sizeof...(_Tp) == 2>,
937 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
938 >::value
939 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400940 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500941 explicit tuple(pair<_Up1, _Up2>&& __p)
942 _NOEXCEPT_((_And<
943 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
944 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
945 >::value))
946 : __base_(_VSTD::move(__p))
947 { }
948
Louis Dionne9ce598d2021-09-08 09:14:43 -0400949 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500950 _And<
951 _BoolConstant<sizeof...(_Tp) == 2>,
952 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
953 >::value
954 , int> = 0>
955 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
956 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
957 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
958 { }
959
Louis Dionne9ce598d2021-09-08 09:14:43 -0400960 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500961 _And<
962 _BoolConstant<sizeof...(_Tp) == 2>,
963 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
964 >::value
965 , int> = 0>
966 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
967 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
968 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
969 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000970
Louis Dionne6c0d5342018-07-31 11:56:20 -0400971 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500972 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400973 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
974 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000975 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400976 _VSTD::__memberwise_copy_assign(*this, __tuple,
977 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000978 return *this;
979 }
980
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500981 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400982 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
983 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000984 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400985 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
986 __tuple_types<_Tp...>(),
987 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000988 return *this;
989 }
990
Louis Dionne9ce598d2021-09-08 09:14:43 -0400991 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -0400992 _And<
993 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
994 is_assignable<_Tp&, _Up const&>...
995 >::value
996 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500997 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400998 tuple& operator=(tuple<_Up...> const& __tuple)
999 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1000 {
1001 _VSTD::__memberwise_copy_assign(*this, __tuple,
1002 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1003 return *this;
1004 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005
Louis Dionne9ce598d2021-09-08 09:14:43 -04001006 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001007 _And<
1008 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1009 is_assignable<_Tp&, _Up>...
1010 >::value
1011 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001012 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001013 tuple& operator=(tuple<_Up...>&& __tuple)
1014 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1015 {
1016 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1017 __tuple_types<_Up...>(),
1018 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1019 return *this;
1020 }
1021
Louis Dionne9ce598d2021-09-08 09:14:43 -04001022 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001023 _And<_Dep,
1024 _BoolConstant<sizeof...(_Tp) == 2>,
1025 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1026 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1027 >::value
1028 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001029 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001030 tuple& operator=(pair<_Up1, _Up2> const& __pair)
1031 _NOEXCEPT_((_And<
1032 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1033 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1034 >::value))
1035 {
1036 _VSTD::get<0>(*this) = __pair.first;
1037 _VSTD::get<1>(*this) = __pair.second;
1038 return *this;
1039 }
1040
Louis Dionne9ce598d2021-09-08 09:14:43 -04001041 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001042 _And<_Dep,
1043 _BoolConstant<sizeof...(_Tp) == 2>,
1044 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1045 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1046 >::value
1047 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001048 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001049 tuple& operator=(pair<_Up1, _Up2>&& __pair)
1050 _NOEXCEPT_((_And<
1051 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1052 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1053 >::value))
1054 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001055 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1056 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001057 return *this;
1058 }
1059
1060 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001061 template<class _Up, size_t _Np, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001062 _And<
1063 _BoolConstant<_Np == sizeof...(_Tp)>,
1064 is_assignable<_Tp&, _Up const&>...
1065 >::value
1066 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001067 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001068 tuple& operator=(array<_Up, _Np> const& __array)
1069 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1070 {
1071 _VSTD::__memberwise_copy_assign(*this, __array,
1072 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1073 return *this;
1074 }
1075
1076 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001077 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001078 _And<
1079 _BoolConstant<_Np == sizeof...(_Tp)>,
1080 is_assignable<_Tp&, _Up>...
1081 >::value
1082 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001083 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001084 tuple& operator=(array<_Up, _Np>&& __array)
1085 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1086 {
1087 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1088 __tuple_types<_If<true, _Up, _Tp>...>(),
1089 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1090 return *this;
1091 }
1092
1093 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001095 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001096 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001097};
1098
1099template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001100class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001101{
1102public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001103 _LIBCPP_INLINE_VISIBILITY constexpr
1104 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001105 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001106 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001107 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001109 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001110 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001111 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001112 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001113 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001114 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001115 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001116 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001117 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001118 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119};
1120
Joe Loserd9b3d972022-03-12 10:46:57 -05001121#if _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001122template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1123 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1124struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1125 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1126};
1127
1128template <class... _TTypes, class... _UTypes>
1129 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1130struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1131 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1132};
Joe Loserd9b3d972022-03-12 10:46:57 -05001133#endif // _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001134
1135#if _LIBCPP_STD_VER > 14
Louis Dionne616da2a2019-08-12 18:30:31 +00001136template <class ..._Tp>
1137tuple(_Tp...) -> tuple<_Tp...>;
1138template <class _Tp1, class _Tp2>
1139tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1140template <class _Alloc, class ..._Tp>
1141tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1142template <class _Alloc, class _Tp1, class _Tp2>
1143tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1144template <class _Alloc, class ..._Tp>
1145tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001146#endif
1147
Howard Hinnantc51e1022010-05-11 19:42:16 +00001148template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001149inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001150typename enable_if
1151<
1152 __all<__is_swappable<_Tp>::value...>::value,
1153 void
1154>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001155swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1156 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1157 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158
1159// get
1160
1161template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001162inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001163typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001164get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001165{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001166 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001167 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168}
1169
1170template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001171inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001172const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001173get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001175 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001176 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001177}
1178
Howard Hinnant22e97242010-11-17 19:52:17 +00001179template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001180inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001181typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001182get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001183{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001184 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001185 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001186 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001187}
1188
Eric Fiselier6dea8092015-12-18 00:36:55 +00001189template <size_t _Ip, class ..._Tp>
1190inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1191const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1192get(const tuple<_Tp...>&& __t) _NOEXCEPT
1193{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001194 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001195 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001196 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001197}
1198
Marshall Clow15b02e02013-07-13 02:54:05 +00001199#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001200
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001201namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001202
Louis Dionne7dd28aa2021-07-20 11:46:05 -04001203static constexpr size_t __not_found = static_cast<size_t>(-1);
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001204static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001205
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001206inline _LIBCPP_INLINE_VISIBILITY
1207constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1208 return !__matches ? __res :
1209 (__res == __not_found ? __curr_i : __ambiguous);
1210}
Marshall Clow15b02e02013-07-13 02:54:05 +00001211
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001212template <size_t _Nx>
1213inline _LIBCPP_INLINE_VISIBILITY
1214constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1215 return __i == _Nx ? __not_found :
1216 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1217}
1218
1219template <class _T1, class ..._Args>
1220struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001221 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001222 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001223 static_assert(value != __not_found, "type not found in type list" );
1224 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001225};
1226
Eric Fiselier8087d302016-07-02 03:46:08 +00001227template <class _T1>
1228struct __find_exactly_one_checked<_T1> {
1229 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1230};
1231
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001232} // namespace __find_detail
Marshall Clow15b02e02013-07-13 02:54:05 +00001233
1234template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001235struct __find_exactly_one_t
1236 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1237};
Marshall Clow15b02e02013-07-13 02:54:05 +00001238
1239template <class _T1, class... _Args>
1240inline _LIBCPP_INLINE_VISIBILITY
1241constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1242{
1243 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1244}
1245
1246template <class _T1, class... _Args>
1247inline _LIBCPP_INLINE_VISIBILITY
1248constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1249{
1250 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1251}
1252
1253template <class _T1, class... _Args>
1254inline _LIBCPP_INLINE_VISIBILITY
1255constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1256{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001257 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001258}
1259
Eric Fiselier6dea8092015-12-18 00:36:55 +00001260template <class _T1, class... _Args>
1261inline _LIBCPP_INLINE_VISIBILITY
1262constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1263{
1264 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1265}
1266
Marshall Clow15b02e02013-07-13 02:54:05 +00001267#endif
1268
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269// tie
1270
1271template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001272inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001273tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001274tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275{
1276 return tuple<_Tp&...>(__t...);
1277}
1278
1279template <class _Up>
1280struct __ignore_t
1281{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001282 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001283 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1284 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285};
1286
Eric Fiselier24e70262017-02-06 01:25:31 +00001287namespace {
Louis Dionne559be102021-09-22 09:35:32 -04001288 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001289} // namespace
Howard Hinnantc51e1022010-05-11 19:42:16 +00001290
Howard Hinnantc51e1022010-05-11 19:42:16 +00001291template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001292inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001293tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294make_tuple(_Tp&&... __t)
1295{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001296 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297}
1298
Howard Hinnant3d203a32010-08-19 18:59:38 +00001299template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001300inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1301tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001302forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001303{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001304 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001305}
1306
Howard Hinnantc834c512011-11-29 18:15:50 +00001307template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308struct __tuple_equal
1309{
1310 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001311 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001312 bool operator()(const _Tp& __x, const _Up& __y)
1313 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001314 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315 }
1316};
1317
1318template <>
1319struct __tuple_equal<0>
1320{
1321 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001322 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323 bool operator()(const _Tp&, const _Up&)
1324 {
1325 return true;
1326 }
1327};
1328
1329template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001330inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001331bool
1332operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1333{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001334 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001335 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1336}
1337
Joe Loserd9b3d972022-03-12 10:46:57 -05001338#if _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001339
1340// operator<=>
1341
1342template <class ..._Tp, class ..._Up, size_t ..._Is>
1343_LIBCPP_HIDE_FROM_ABI constexpr
1344auto
1345__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1346 common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1347 static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1348 return __result;
1349}
1350
1351template <class ..._Tp, class ..._Up>
1352requires (sizeof...(_Tp) == sizeof...(_Up))
1353_LIBCPP_HIDE_FROM_ABI constexpr
1354common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1355operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1356{
1357 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1358}
1359
Joe Loserd9b3d972022-03-12 10:46:57 -05001360#else // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001361
Howard Hinnantc51e1022010-05-11 19:42:16 +00001362template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001363inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364bool
1365operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1366{
1367 return !(__x == __y);
1368}
1369
Howard Hinnantc834c512011-11-29 18:15:50 +00001370template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371struct __tuple_less
1372{
1373 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001374 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375 bool operator()(const _Tp& __x, const _Up& __y)
1376 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001377 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1378 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1379 return true;
1380 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1381 return false;
1382 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001383 }
1384};
1385
1386template <>
1387struct __tuple_less<0>
1388{
1389 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001390 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001391 bool operator()(const _Tp&, const _Up&)
1392 {
1393 return false;
1394 }
1395};
1396
1397template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001398inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399bool
1400operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1401{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001402 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001403 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1404}
1405
1406template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001407inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001408bool
1409operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1410{
1411 return __y < __x;
1412}
1413
1414template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001415inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001416bool
1417operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1418{
1419 return !(__x < __y);
1420}
1421
1422template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001423inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424bool
1425operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1426{
1427 return !(__y < __x);
1428}
1429
Joe Loserd9b3d972022-03-12 10:46:57 -05001430#endif // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001431
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432// tuple_cat
1433
Howard Hinnant6256ee72010-12-11 20:47:50 +00001434template <class _Tp, class _Up> struct __tuple_cat_type;
1435
1436template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001437struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001438{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001439 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001440};
1441
1442template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1443struct __tuple_cat_return_1
1444{
1445};
1446
1447template <class ..._Types, class _Tuple0>
1448struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1449{
Nikolas Klauser669b4452022-02-17 22:53:20 +01001450 using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
1451 tuple<_Types...>,
1452 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
1453 >::type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001454};
1455
1456template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1457struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1458 : public __tuple_cat_return_1<
1459 typename __tuple_cat_type<
1460 tuple<_Types...>,
Nikolas Klauser669b4452022-02-17 22:53:20 +01001461 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001462 >::type,
1463 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1464 _Tuple1, _Tuples...>
1465{
1466};
1467
1468template <class ..._Tuples> struct __tuple_cat_return;
1469
1470template <class _Tuple0, class ..._Tuples>
1471struct __tuple_cat_return<_Tuple0, _Tuples...>
1472 : public __tuple_cat_return_1<tuple<>,
1473 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1474 _Tuples...>
1475{
1476};
1477
1478template <>
1479struct __tuple_cat_return<>
1480{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001481 typedef _LIBCPP_NODEBUG tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001482};
1483
Marshall Clow2229cee2013-07-22 16:02:19 +00001484inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001485tuple<>
1486tuple_cat()
1487{
1488 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001489}
1490
Howard Hinnantc834c512011-11-29 18:15:50 +00001491template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001492struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493
Howard Hinnant21376f62010-12-12 23:04:37 +00001494template <class ..._Types, size_t ..._I0, class _Tuple0>
1495struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001496{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001497 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001498 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1499 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1500};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501
Howard Hinnant21376f62010-12-12 23:04:37 +00001502template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1503struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1504 _Tuple0, _Tuple1, _Tuples...>
1505 : public __tuple_cat_return_ref_imp<
1506 tuple<_Types..., typename __apply_cv<_Tuple0,
1507 typename tuple_element<_I0,
1508 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1509 typename __make_tuple_indices<tuple_size<typename
1510 remove_reference<_Tuple1>::type>::value>::type,
1511 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512{
Howard Hinnant21376f62010-12-12 23:04:37 +00001513};
1514
1515template <class _Tuple0, class ..._Tuples>
1516struct __tuple_cat_return_ref
1517 : public __tuple_cat_return_ref_imp<tuple<>,
1518 typename __make_tuple_indices<
1519 tuple_size<typename remove_reference<_Tuple0>::type>::value
1520 >::type, _Tuple0, _Tuples...>
1521{
1522};
1523
1524template <class _Types, class _I0, class _J0>
1525struct __tuple_cat;
1526
1527template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001528struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001529{
1530 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001531 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001532 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1533 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1534 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001535 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
David Blaikie699a5e22019-10-28 18:03:59 -07001536 return _VSTD::forward_as_tuple(
1537 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1538 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001539 }
1540
1541 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001542 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001543 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1544 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1545 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001546 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001547 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1548 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001549 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001550 tuple<_Types...,
1551 typename __apply_cv<_Tuple0, typename tuple_element<
1552 _J0, _T0>::type>::type&&...>,
1553 typename __make_tuple_indices<sizeof...(_Types) +
1554 tuple_size<_T0>::value>::type,
1555 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1556 _VSTD::forward_as_tuple(
1557 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1558 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1559 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001560 }
1561};
1562
1563template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001564inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001565typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1566tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1567{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001568 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001569 return __tuple_cat<tuple<>, __tuple_indices<>,
1570 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001571 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1572 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573}
1574
1575template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001576struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577 : true_type {};
1578
Howard Hinnantc51e1022010-05-11 19:42:16 +00001579template <class _T1, class _T2>
1580template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001581inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582pair<_T1, _T2>::pair(piecewise_construct_t,
1583 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1584 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001585 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1586 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587{
1588}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589
Eric Fiselier8e892c52016-07-18 00:35:56 +00001590#if _LIBCPP_STD_VER > 14
1591template <class _Tp>
Louis Dionne559be102021-09-22 09:35:32 -04001592inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001593
1594#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1595
1596template <class _Fn, class _Tuple, size_t ..._Id>
1597inline _LIBCPP_INLINE_VISIBILITY
1598constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1599 __tuple_indices<_Id...>)
1600_LIBCPP_NOEXCEPT_RETURN(
Nikolas Klausera28f48e2022-04-06 23:10:21 +02001601 _VSTD::__invoke(
Eric Fiselier8e892c52016-07-18 00:35:56 +00001602 _VSTD::forward<_Fn>(__f),
1603 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1604)
1605
1606template <class _Fn, class _Tuple>
1607inline _LIBCPP_INLINE_VISIBILITY
1608constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1609_LIBCPP_NOEXCEPT_RETURN(
1610 _VSTD::__apply_tuple_impl(
1611 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001612 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001613)
1614
1615template <class _Tp, class _Tuple, size_t... _Idx>
1616inline _LIBCPP_INLINE_VISIBILITY
1617constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1618_LIBCPP_NOEXCEPT_RETURN(
1619 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1620)
1621
1622template <class _Tp, class _Tuple>
1623inline _LIBCPP_INLINE_VISIBILITY
1624constexpr _Tp make_from_tuple(_Tuple&& __t)
1625_LIBCPP_NOEXCEPT_RETURN(
1626 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001627 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001628)
1629
1630#undef _LIBCPP_NOEXCEPT_RETURN
1631
1632#endif // _LIBCPP_STD_VER > 14
1633
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001634#endif // !defined(_LIBCPP_CXX03_LANG)
1635
Howard Hinnantc51e1022010-05-11 19:42:16 +00001636_LIBCPP_END_NAMESPACE_STD
1637
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001638#endif // _LIBCPP_TUPLE