blob: a28a2e81db3ecfd2231f5455e17ee902c29891c8 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
Chandler Carruth7642bb12019-01-19 08:50:56 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TUPLE
11#define _LIBCPP_TUPLE
12
13/*
14 tuple synopsis
15
16namespace std
17{
18
19template <class... T>
20class tuple {
21public:
Louis Dionnea7a2beb2019-09-26 14:51:10 +000022 explicit(see-below) constexpr tuple();
Louis Dionne1afad1d2019-07-22 20:45:23 +000023 explicit(see-below) tuple(const T&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000024 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000025 explicit(see-below) tuple(U&&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000026 tuple(const tuple&) = default;
Howard Hinnant89ef1212011-05-27 19:08:18 +000027 tuple(tuple&&) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +000028 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000029 explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000030 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000031 explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000033 explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000034 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000035 explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000036
37 // allocator-extended constructors
38 template <class Alloc>
39 tuple(allocator_arg_t, const Alloc& a);
40 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050041 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050043 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000044 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050045 tuple(allocator_arg_t, const Alloc& a, const tuple&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000046 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050047 tuple(allocator_arg_t, const Alloc& a, tuple&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000048 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050049 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000050 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050051 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000052 template <class Alloc, class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050053 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000054 template <class Alloc, class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050055 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050057 tuple& operator=(const tuple&); // constexpr in C++20
58 tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000059 template <class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050060 tuple& operator=(const tuple<U...>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000061 template <class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050062 tuple& operator=(tuple<U...>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000063 template <class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050064 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000065 template <class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050066 tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000067
Louis Dionne6c0d5342018-07-31 11:56:20 -040068 template<class U, size_t N>
69 tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
70 template<class U, size_t N>
71 tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
72
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050073 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000074};
75
Nikolas Klauserad26ba52022-01-17 19:45:42 +010076
77template<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23
78 requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }
79struct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {
80 using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
81};
82
83template<class... TTypes, class... UTypes> // since C++23
84 requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }
85struct common_type<tuple<TTypes...>, tuple<UTypes...>> {
86 using type = tuple<common_type_t<TTypes, UTypes>...>;
87};
88
Louis Dionne616da2a2019-08-12 18:30:31 +000089template <class ...T>
90tuple(T...) -> tuple<T...>; // since C++17
91template <class T1, class T2>
92tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
93template <class Alloc, class ...T>
94tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
95template <class Alloc, class T1, class T2>
96tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
97template <class Alloc, class ...T>
98tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
99
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000100inline constexpr unspecified ignore;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000101
Marshall Clow2229cee2013-07-22 16:02:19 +0000102template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clowded420b2013-10-05 18:46:37 +0000103template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clowa8892812014-02-25 16:11:46 +0000104template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clow2229cee2013-07-22 16:02:19 +0000105template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier8e892c52016-07-18 00:35:56 +0000106
107// [tuple.apply], calling a function with a tuple of arguments:
108template <class F, class Tuple>
109 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
110template <class T, class Tuple>
111 constexpr T make_from_tuple(Tuple&& t); // C++17
112
Howard Hinnantc51e1022010-05-11 19:42:16 +0000113// 20.4.1.4, tuple helper classes:
Marshall Clowce62b4d2019-01-11 21:57:12 +0000114template <class T> struct tuple_size; // undefined
115template <class... T> struct tuple_size<tuple<T...>>;
Eric Fiselier8e892c52016-07-18 00:35:56 +0000116template <class T>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000117 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Louis Dionnee684aa62019-04-01 16:39:34 +0000118template <size_t I, class T> struct tuple_element; // undefined
119template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
Marshall Clow36907512015-11-19 19:45:29 +0000120template <size_t I, class T>
121 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000122
123// 20.4.1.5, element access:
Marshall Clow36907512015-11-19 19:45:29 +0000124template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000125 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000126 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000127template <size_t I, class... T>
128 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000129 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000130template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000131 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow0abb1042013-07-17 18:25:36 +0000132 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000133template <size_t I, class... T>
134 const typename tuple_element<I, tuple<T...>>::type&&
135 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136
Marshall Clow15b02e02013-07-13 02:54:05 +0000137template <class T1, class... T>
138 constexpr T1& get(tuple<T...>&) noexcept; // C++14
139template <class T1, class... T>
Marshall Clow36907512015-11-19 19:45:29 +0000140 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000141template <class T1, class... T>
142 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000143template <class T1, class... T>
144 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000145
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146// 20.4.1.6, relational operators:
Marshall Clow2229cee2013-07-22 16:02:19 +0000147template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Kent Ross0861b0d2021-10-08 14:54:28 -0700148template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
149template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
150template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
151template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
152template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
153template<class... T, class... U>
154 constexpr common_comparison_category_t<synth-three-way-result<T, U>...>
155 operator<=>(const tuple<T...>&, const tuple<U...>&); // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156
157template <class... Types, class Alloc>
158 struct uses_allocator<tuple<Types...>, Alloc>;
159
160template <class... Types>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000161 void
162 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164} // std
165
166*/
167
Kent Ross0861b0d2021-10-08 14:54:28 -0700168#include <__compare/common_comparison_category.h>
169#include <__compare/synth_three_way.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170#include <__config>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000171#include <__functional/unwrap_ref.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400172#include <__memory/allocator_arg_t.h>
173#include <__memory/uses_allocator.h>
174#include <__tuple>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000175#include <__utility/forward.h>
Kent Ross0861b0d2021-10-08 14:54:28 -0700176#include <__utility/integer_sequence.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000177#include <__utility/move.h>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400178#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000181#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000182#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000183
Nikolas Klauser4c1bf592022-02-11 19:15:18 +0100184// TODO: remove these headers
185#include <__functional/binary_function.h>
186#include <__functional/invoke.h>
187#include <__functional/operations.h>
188#include <__functional/reference_wrapper.h>
189#include <__functional/unary_function.h>
190#include <__functional/weak_result_type.h>
191#include <exception>
192#include <new>
193#include <typeinfo>
194
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000195#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500196# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000197#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198
199_LIBCPP_BEGIN_NAMESPACE_STD
200
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000201#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202
Marshall Clowf50d66f2014-03-03 06:18:11 +0000203
Howard Hinnantc51e1022010-05-11 19:42:16 +0000204// __tuple_leaf
205
Eric Fiselierf7394302015-06-13 07:08:02 +0000206template <size_t _Ip, class _Hp,
207 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000208 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000209class __tuple_leaf;
210
211template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500212inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000214 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215{
216 swap(__x.get(), __y.get());
217}
218
219template <size_t _Ip, class _Hp, bool>
220class __tuple_leaf
221{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000222 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000223
Eric Fiselierca8bba12016-07-20 02:57:39 +0000224 template <class _Tp>
225 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000226#if __has_keyword(__reference_binds_to_temporary)
227 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000228#else
229 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000230#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000231 }
232
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500233 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234 __tuple_leaf& operator=(const __tuple_leaf&);
235public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500236 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000237 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000238 {static_assert(!is_reference<_Hp>::value,
239 "Attempted to default construct a reference element in a tuple");}
240
241 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500242 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000244 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245 {static_assert(!is_reference<_Hp>::value,
246 "Attempted to default construct a reference element in a tuple");}
247
248 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500249 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000251 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000252 {static_assert(!is_reference<_Hp>::value,
253 "Attempted to default construct a reference element in a tuple");}
254
255 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500256 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000258 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259 {static_assert(!is_reference<_Hp>::value,
260 "Attempted to default construct a reference element in a tuple");}
261
Howard Hinnant693fc212010-09-27 17:54:17 +0000262 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400263 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000264 _And<
265 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
266 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000267 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000268 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000269 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000270 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000271 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000272 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000273 {static_assert(__can_bind_reference<_Tp&&>(),
274 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275
276 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500277 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000279 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000280 {static_assert(__can_bind_reference<_Tp&&>(),
281 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282
283 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500284 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000286 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000287 {static_assert(!is_reference<_Hp>::value,
288 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289
290 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500291 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000293 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000294 {static_assert(!is_reference<_Hp>::value,
295 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296
Marshall Clow47fcee52014-04-21 23:48:09 +0000297 __tuple_leaf(const __tuple_leaf& __t) = default;
298 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000299
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500300 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000301 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000303 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304 return 0;
305 }
306
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000307 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
308 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309};
310
311template <size_t _Ip, class _Hp>
312class __tuple_leaf<_Ip, _Hp, true>
313 : private _Hp
314{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500315 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316 __tuple_leaf& operator=(const __tuple_leaf&);
317public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500318 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000319 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320
321 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500322 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000323 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
324
325 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500326 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
328 : _Hp(allocator_arg_t(), __a) {}
329
330 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500331 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
333 : _Hp(__a) {}
334
Howard Hinnant693fc212010-09-27 17:54:17 +0000335 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400336 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000337 _And<
338 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
339 is_constructible<_Hp, _Tp>
340 >::value
341 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000342 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000343 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000344 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000345 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346
347 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500348 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000350 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351
352 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500353 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000355 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356
357 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500358 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000360 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000361
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000362 __tuple_leaf(__tuple_leaf const &) = default;
363 __tuple_leaf(__tuple_leaf &&) = default;
364
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500365 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000366 int
367 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000369 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370 return 0;
371 }
372
Marshall Clow2229cee2013-07-22 16:02:19 +0000373 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
374 _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 +0000375};
376
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000377template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500378_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000379void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000380
Marshall Clowc470eae2014-10-15 10:33:02 +0000381template <class _Tp>
382struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000383
Marshall Clowc470eae2014-10-15 10:33:02 +0000384template <class ..._Tp>
385struct __all_default_constructible<__tuple_types<_Tp...>>
386 : __all<is_default_constructible<_Tp>::value...>
387{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000388
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389// __tuple_impl
390
391template<class _Indx, class ..._Tp> struct __tuple_impl;
392
393template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000394struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 : public __tuple_leaf<_Indx, _Tp>...
396{
Howard Hinnant38469632012-07-06 20:39:45 +0000397 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500398 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000399 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000400
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401 template <size_t ..._Uf, class ..._Tf,
402 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000403 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404 explicit
405 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
406 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000407 _Up&&... __u)
408 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
409 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000410 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 __tuple_leaf<_Ul, _Tl>()...
412 {}
413
414 template <class _Alloc, size_t ..._Uf, class ..._Tf,
415 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500416 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000417 explicit
418 __tuple_impl(allocator_arg_t, const _Alloc& __a,
419 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
420 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
421 _Up&&... __u) :
422 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000423 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
425 {}
426
427 template <class _Tuple,
428 class = typename enable_if
429 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000430 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431 >::type
432 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000433 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000434 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
435 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000436 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
437 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438 {}
439
440 template <class _Alloc, class _Tuple,
441 class = typename enable_if
442 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000443 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444 >::type
445 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500446 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
448 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000449 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000450 _VSTD::forward<typename tuple_element<_Indx,
451 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452 {}
453
Howard Hinnant0d032d12013-11-06 17:45:43 +0000454 __tuple_impl(const __tuple_impl&) = default;
455 __tuple_impl(__tuple_impl&&) = default;
456
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500457 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000459 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400461 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000462 }
463};
464
Louis Dionne6c0d5342018-07-31 11:56:20 -0400465template<class _Dest, class _Source, 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_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
468 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
469}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000470
Louis Dionne6c0d5342018-07-31 11:56:20 -0400471template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500472_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400473void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
474 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500475 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400476 ), void(), 0)...);
477}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000478
Howard Hinnantc51e1022010-05-11 19:42:16 +0000479template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000480class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000481{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000482 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000484 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485
Marshall Clow0abb1042013-07-17 18:25:36 +0000486 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000487 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000488 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000489 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000490 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000491 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000492 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
493 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500495 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496
Louis Dionne574e2e32021-02-10 16:19:50 -0500497 // tuple() constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400498 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500499 _And<
500 _IsImpDefault<_Tp>... // explicit check
501 >::value
502 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400503 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000504 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500505 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
506 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000507
Louis Dionne574e2e32021-02-10 16:19:50 -0500508 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400509 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500510 _And<
511 _IsDefault<_Tp>...,
512 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
513 >::value
514 , int> = 0>
515 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
516 explicit tuple()
517 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
518 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000519
Louis Dionne9ce598d2021-09-08 09:14:43 -0400520 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500521 _And<
522 _IsImpDefault<_Tp>... // explicit check
523 >::value
524 , int> = 0>
525 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
526 tuple(allocator_arg_t, _Alloc const& __a)
527 : __base_(allocator_arg_t(), __a,
528 __tuple_indices<>(), __tuple_types<>(),
529 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
530 __tuple_types<_Tp...>()) {}
531
532 template <class _Alloc,
533 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400534 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500535 _And<
536 _IsDefault<_Tp>...,
537 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
538 >::value
539 , int> = 0>
540 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
541 explicit tuple(allocator_arg_t, _Alloc const& __a)
542 : __base_(allocator_arg_t(), __a,
543 __tuple_indices<>(), __tuple_types<>(),
544 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
545 __tuple_types<_Tp...>()) {}
546
547 // tuple(const T&...) constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400548 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500549 _And<
550 _BoolConstant<sizeof...(_Tp) >= 1>,
551 is_copy_constructible<_Tp>...,
552 is_convertible<const _Tp&, _Tp>... // explicit check
553 >::value
554 , int> = 0>
555 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
556 tuple(const _Tp& ... __t)
557 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
558 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
559 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
560 typename __make_tuple_indices<0>::type(),
561 typename __make_tuple_types<tuple, 0>::type(),
562 __t...
563 ) {}
564
Louis Dionne9ce598d2021-09-08 09:14:43 -0400565 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500566 _And<
567 _BoolConstant<sizeof...(_Tp) >= 1>,
568 is_copy_constructible<_Tp>...,
569 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
570 >::value
571 , int> = 0>
572 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
573 explicit tuple(const _Tp& ... __t)
574 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
575 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
576 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
577 typename __make_tuple_indices<0>::type(),
578 typename __make_tuple_types<tuple, 0>::type(),
579 __t...
580 ) {}
581
Louis Dionne9ce598d2021-09-08 09:14:43 -0400582 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500583 _And<
584 _BoolConstant<sizeof...(_Tp) >= 1>,
585 is_copy_constructible<_Tp>...,
586 is_convertible<const _Tp&, _Tp>... // explicit check
587 >::value
588 , int> = 0>
589 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
590 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
591 : __base_(allocator_arg_t(), __a,
592 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
593 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
594 typename __make_tuple_indices<0>::type(),
595 typename __make_tuple_types<tuple, 0>::type(),
596 __t...
597 ) {}
598
Louis Dionne9ce598d2021-09-08 09:14:43 -0400599 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500600 _And<
601 _BoolConstant<sizeof...(_Tp) >= 1>,
602 is_copy_constructible<_Tp>...,
603 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
604 >::value
605 , int> = 0>
606 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
607 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
608 : __base_(allocator_arg_t(), __a,
609 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
610 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
611 typename __make_tuple_indices<0>::type(),
612 typename __make_tuple_types<tuple, 0>::type(),
613 __t...
614 ) {}
615
616 // tuple(U&& ...) constructors (including allocator_arg_t variants)
617 template <class ..._Up> struct _IsThisTuple : false_type { };
618 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
619
620 template <class ..._Up>
621 struct _EnableUTypesCtor : _And<
622 _BoolConstant<sizeof...(_Tp) >= 1>,
623 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
624 is_constructible<_Tp, _Up>...
625 > { };
626
Louis Dionne9ce598d2021-09-08 09:14:43 -0400627 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500628 _And<
629 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
630 _EnableUTypesCtor<_Up...>,
631 is_convertible<_Up, _Tp>... // explicit check
632 >::value
633 , int> = 0>
634 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
635 tuple(_Up&&... __u)
636 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
637 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
638 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
639 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
640 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
641 _VSTD::forward<_Up>(__u)...) {}
642
Louis Dionne9ce598d2021-09-08 09:14:43 -0400643 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500644 _And<
645 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
646 _EnableUTypesCtor<_Up...>,
647 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
648 >::value
649 , int> = 0>
650 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
651 explicit tuple(_Up&&... __u)
652 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
653 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
654 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
655 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
656 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
657 _VSTD::forward<_Up>(__u)...) {}
658
Louis Dionne9ce598d2021-09-08 09:14:43 -0400659 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500660 _And<
661 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
662 _EnableUTypesCtor<_Up...>,
663 is_convertible<_Up, _Tp>... // explicit check
664 >::value
665 , int> = 0>
666 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
667 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
668 : __base_(allocator_arg_t(), __a,
669 typename __make_tuple_indices<sizeof...(_Up)>::type(),
670 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
671 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
672 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
673 _VSTD::forward<_Up>(__u)...) {}
674
Louis Dionne9ce598d2021-09-08 09:14:43 -0400675 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500676 _And<
677 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
678 _EnableUTypesCtor<_Up...>,
679 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
680 >::value
681 , int> = 0>
682 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
683 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
684 : __base_(allocator_arg_t(), __a,
685 typename __make_tuple_indices<sizeof...(_Up)>::type(),
686 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
687 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
688 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
689 _VSTD::forward<_Up>(__u)...) {}
690
691 // Copy and move constructors (including the allocator_arg_t variants)
692 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000693 tuple(tuple&&) = default;
694
Louis Dionne9ce598d2021-09-08 09:14:43 -0400695 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500696 _And<is_copy_constructible<_Tp>...>::value
697 , int> = 0>
698 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
699 : __base_(allocator_arg_t(), __alloc, __t)
700 { }
701
Louis Dionne9ce598d2021-09-08 09:14:43 -0400702 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500703 _And<is_move_constructible<_Tp>...>::value
704 , int> = 0>
705 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
706 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
707 { }
708
709 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
710 template <class ..._Up>
711 struct _EnableCopyFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400712 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
713 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500714 _BoolConstant<sizeof...(_Tp) != 1>,
715 // _Tp and _Up are 1-element packs - the pack expansions look
716 // weird to avoid tripping up the type traits in degenerate cases
717 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500718 _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
719 _Not<is_constructible<_Tp, const tuple<_Up>&> >...
720 >
721 >,
722 is_constructible<_Tp, const _Up&>...
723 > { };
724
Louis Dionne9ce598d2021-09-08 09:14:43 -0400725 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500726 _And<
727 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
728 _EnableCopyFromOtherTuple<_Up...>,
729 is_convertible<const _Up&, _Tp>... // explicit check
730 >::value
731 , int> = 0>
732 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
733 tuple(const tuple<_Up...>& __t)
734 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
735 : __base_(__t)
736 { }
737
Louis Dionne9ce598d2021-09-08 09:14:43 -0400738 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500739 _And<
740 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
741 _EnableCopyFromOtherTuple<_Up...>,
742 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
743 >::value
744 , int> = 0>
745 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
746 explicit tuple(const tuple<_Up...>& __t)
747 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
748 : __base_(__t)
749 { }
750
Louis Dionne9ce598d2021-09-08 09:14:43 -0400751 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500752 _And<
753 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
754 _EnableCopyFromOtherTuple<_Up...>,
755 is_convertible<const _Up&, _Tp>... // explicit check
756 >::value
757 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500758 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500759 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
760 : __base_(allocator_arg_t(), __a, __t)
761 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000762
Louis Dionne9ce598d2021-09-08 09:14:43 -0400763 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500764 _And<
765 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
766 _EnableCopyFromOtherTuple<_Up...>,
767 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
768 >::value
769 , int> = 0>
770 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
771 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
772 : __base_(allocator_arg_t(), __a, __t)
773 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000774
Louis Dionne574e2e32021-02-10 16:19:50 -0500775 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
776 template <class ..._Up>
777 struct _EnableMoveFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400778 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
779 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500780 _BoolConstant<sizeof...(_Tp) != 1>,
781 // _Tp and _Up are 1-element packs - the pack expansions look
782 // weird to avoid tripping up the type traits in degenerate cases
783 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500784 _Not<is_convertible<tuple<_Up>, _Tp> >...,
785 _Not<is_constructible<_Tp, tuple<_Up> > >...
786 >
787 >,
788 is_constructible<_Tp, _Up>...
789 > { };
790
Louis Dionne9ce598d2021-09-08 09:14:43 -0400791 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500792 _And<
793 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
794 _EnableMoveFromOtherTuple<_Up...>,
795 is_convertible<_Up, _Tp>... // explicit check
796 >::value
797 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000798 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500799 tuple(tuple<_Up...>&& __t)
800 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
801 : __base_(_VSTD::move(__t))
802 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803
Louis Dionne9ce598d2021-09-08 09:14:43 -0400804 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500805 _And<
806 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
807 _EnableMoveFromOtherTuple<_Up...>,
808 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
809 >::value
810 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000811 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500812 explicit tuple(tuple<_Up...>&& __t)
813 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
814 : __base_(_VSTD::move(__t))
815 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000816
Louis Dionne9ce598d2021-09-08 09:14:43 -0400817 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500818 _And<
819 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
820 _EnableMoveFromOtherTuple<_Up...>,
821 is_convertible<_Up, _Tp>... // explicit check
822 >::value
823 , int> = 0>
824 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
825 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
826 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
827 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828
Louis Dionne9ce598d2021-09-08 09:14:43 -0400829 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500830 _And<
831 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
832 _EnableMoveFromOtherTuple<_Up...>,
833 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
834 >::value
835 , int> = 0>
836 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
837 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
838 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
839 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000840
Louis Dionne574e2e32021-02-10 16:19:50 -0500841 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
842 template <class _Up1, class _Up2, class ..._DependentTp>
843 struct _EnableImplicitCopyFromPair : _And<
844 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
845 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
846 is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
847 is_convertible<const _Up2&, _SecondType<_DependentTp...> >
848 > { };
Howard Hinnant65704d02012-04-01 23:10:42 +0000849
Louis Dionne574e2e32021-02-10 16:19:50 -0500850 template <class _Up1, class _Up2, class ..._DependentTp>
851 struct _EnableExplicitCopyFromPair : _And<
852 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
853 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
854 _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
855 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
856 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857
Louis Dionne9ce598d2021-09-08 09:14:43 -0400858 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500859 _And<
860 _BoolConstant<sizeof...(_Tp) == 2>,
861 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
862 >::value
863 , int> = 0>
864 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
865 tuple(const pair<_Up1, _Up2>& __p)
866 _NOEXCEPT_((_And<
867 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
868 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
869 >::value))
870 : __base_(__p)
871 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872
Louis Dionne9ce598d2021-09-08 09:14:43 -0400873 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500874 _And<
875 _BoolConstant<sizeof...(_Tp) == 2>,
876 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
877 >::value
878 , int> = 0>
879 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
880 explicit tuple(const pair<_Up1, _Up2>& __p)
881 _NOEXCEPT_((_And<
882 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
883 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
884 >::value))
885 : __base_(__p)
886 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000887
Louis Dionne9ce598d2021-09-08 09:14:43 -0400888 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500889 _And<
890 _BoolConstant<sizeof...(_Tp) == 2>,
891 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
892 >::value
893 , int> = 0>
894 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
895 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
896 : __base_(allocator_arg_t(), __a, __p)
897 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898
Louis Dionne9ce598d2021-09-08 09:14:43 -0400899 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500900 _And<
901 _BoolConstant<sizeof...(_Tp) == 2>,
902 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
903 >::value
904 , int> = 0>
905 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
906 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
907 : __base_(allocator_arg_t(), __a, __p)
908 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000909
Louis Dionne574e2e32021-02-10 16:19:50 -0500910 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
911 template <class _Up1, class _Up2, class ..._DependentTp>
912 struct _EnableImplicitMoveFromPair : _And<
913 is_constructible<_FirstType<_DependentTp...>, _Up1>,
914 is_constructible<_SecondType<_DependentTp...>, _Up2>,
915 is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
916 is_convertible<_Up2, _SecondType<_DependentTp...> >
917 > { };
Eric Fiselierec5a2102019-07-12 23:01:48 +0000918
Louis Dionne574e2e32021-02-10 16:19:50 -0500919 template <class _Up1, class _Up2, class ..._DependentTp>
920 struct _EnableExplicitMoveFromPair : _And<
921 is_constructible<_FirstType<_DependentTp...>, _Up1>,
922 is_constructible<_SecondType<_DependentTp...>, _Up2>,
923 _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
924 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
925 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000926
Louis Dionne9ce598d2021-09-08 09:14:43 -0400927 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500928 _And<
929 _BoolConstant<sizeof...(_Tp) == 2>,
930 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
931 >::value
932 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400933 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500934 tuple(pair<_Up1, _Up2>&& __p)
935 _NOEXCEPT_((_And<
936 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
937 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
938 >::value))
939 : __base_(_VSTD::move(__p))
940 { }
941
Louis Dionne9ce598d2021-09-08 09:14:43 -0400942 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500943 _And<
944 _BoolConstant<sizeof...(_Tp) == 2>,
945 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
946 >::value
947 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400948 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500949 explicit tuple(pair<_Up1, _Up2>&& __p)
950 _NOEXCEPT_((_And<
951 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
952 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
953 >::value))
954 : __base_(_VSTD::move(__p))
955 { }
956
Louis Dionne9ce598d2021-09-08 09:14:43 -0400957 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500958 _And<
959 _BoolConstant<sizeof...(_Tp) == 2>,
960 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
961 >::value
962 , int> = 0>
963 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
964 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
965 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
966 { }
967
Louis Dionne9ce598d2021-09-08 09:14:43 -0400968 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500969 _And<
970 _BoolConstant<sizeof...(_Tp) == 2>,
971 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
972 >::value
973 , int> = 0>
974 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
975 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
976 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
977 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000978
Louis Dionne6c0d5342018-07-31 11:56:20 -0400979 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500980 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400981 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
982 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000983 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400984 _VSTD::__memberwise_copy_assign(*this, __tuple,
985 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000986 return *this;
987 }
988
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500989 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400990 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
991 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000992 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400993 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
994 __tuple_types<_Tp...>(),
995 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000996 return *this;
997 }
998
Louis Dionne9ce598d2021-09-08 09:14:43 -0400999 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001000 _And<
1001 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1002 is_assignable<_Tp&, _Up const&>...
1003 >::value
1004 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001005 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001006 tuple& operator=(tuple<_Up...> const& __tuple)
1007 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1008 {
1009 _VSTD::__memberwise_copy_assign(*this, __tuple,
1010 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1011 return *this;
1012 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013
Louis Dionne9ce598d2021-09-08 09:14:43 -04001014 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001015 _And<
1016 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1017 is_assignable<_Tp&, _Up>...
1018 >::value
1019 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001020 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001021 tuple& operator=(tuple<_Up...>&& __tuple)
1022 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1023 {
1024 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1025 __tuple_types<_Up...>(),
1026 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1027 return *this;
1028 }
1029
Louis Dionne9ce598d2021-09-08 09:14:43 -04001030 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001031 _And<_Dep,
1032 _BoolConstant<sizeof...(_Tp) == 2>,
1033 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1034 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1035 >::value
1036 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001037 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001038 tuple& operator=(pair<_Up1, _Up2> const& __pair)
1039 _NOEXCEPT_((_And<
1040 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1041 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1042 >::value))
1043 {
1044 _VSTD::get<0>(*this) = __pair.first;
1045 _VSTD::get<1>(*this) = __pair.second;
1046 return *this;
1047 }
1048
Louis Dionne9ce598d2021-09-08 09:14:43 -04001049 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001050 _And<_Dep,
1051 _BoolConstant<sizeof...(_Tp) == 2>,
1052 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1053 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1054 >::value
1055 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001056 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001057 tuple& operator=(pair<_Up1, _Up2>&& __pair)
1058 _NOEXCEPT_((_And<
1059 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1060 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1061 >::value))
1062 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001063 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1064 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001065 return *this;
1066 }
1067
1068 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001069 template<class _Up, size_t _Np, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001070 _And<
1071 _BoolConstant<_Np == sizeof...(_Tp)>,
1072 is_assignable<_Tp&, _Up const&>...
1073 >::value
1074 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001075 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001076 tuple& operator=(array<_Up, _Np> const& __array)
1077 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1078 {
1079 _VSTD::__memberwise_copy_assign(*this, __array,
1080 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1081 return *this;
1082 }
1083
1084 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001085 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001086 _And<
1087 _BoolConstant<_Np == sizeof...(_Tp)>,
1088 is_assignable<_Tp&, _Up>...
1089 >::value
1090 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001091 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001092 tuple& operator=(array<_Up, _Np>&& __array)
1093 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1094 {
1095 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1096 __tuple_types<_If<true, _Up, _Tp>...>(),
1097 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1098 return *this;
1099 }
1100
1101 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001102 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001103 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001104 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001105};
1106
1107template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001108class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109{
1110public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001111 _LIBCPP_INLINE_VISIBILITY constexpr
1112 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001113 template <class _Alloc>
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(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001117 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001118 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001119 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001120 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001121 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001122 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001123 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001124 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001125 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001126 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001127};
1128
Arthur O'Dwyer73541c72022-02-02 11:19:46 -05001129#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001130template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1131 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1132struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1133 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1134};
1135
1136template <class... _TTypes, class... _UTypes>
1137 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1138struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1139 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1140};
Arthur O'Dwyer73541c72022-02-02 11:19:46 -05001141#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001142
1143#if _LIBCPP_STD_VER > 14
Louis Dionne616da2a2019-08-12 18:30:31 +00001144template <class ..._Tp>
1145tuple(_Tp...) -> tuple<_Tp...>;
1146template <class _Tp1, class _Tp2>
1147tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1148template <class _Alloc, class ..._Tp>
1149tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1150template <class _Alloc, class _Tp1, class _Tp2>
1151tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1152template <class _Alloc, class ..._Tp>
1153tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001154#endif
1155
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001157inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001158typename enable_if
1159<
1160 __all<__is_swappable<_Tp>::value...>::value,
1161 void
1162>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001163swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1164 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1165 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166
1167// get
1168
1169template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001170inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001171typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001172get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001173{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001174 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001175 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176}
1177
1178template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001179inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001180const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001181get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001183 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001184 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001185}
1186
Howard Hinnant22e97242010-11-17 19:52:17 +00001187template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001188inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001189typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001190get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001191{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001192 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001193 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001194 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001195}
1196
Eric Fiselier6dea8092015-12-18 00:36:55 +00001197template <size_t _Ip, class ..._Tp>
1198inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1199const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1200get(const tuple<_Tp...>&& __t) _NOEXCEPT
1201{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001202 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001203 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001204 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001205}
1206
Marshall Clow15b02e02013-07-13 02:54:05 +00001207#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001208
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001209namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001210
Louis Dionne7dd28aa2021-07-20 11:46:05 -04001211static constexpr size_t __not_found = static_cast<size_t>(-1);
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001212static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001213
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001214inline _LIBCPP_INLINE_VISIBILITY
1215constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1216 return !__matches ? __res :
1217 (__res == __not_found ? __curr_i : __ambiguous);
1218}
Marshall Clow15b02e02013-07-13 02:54:05 +00001219
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001220template <size_t _Nx>
1221inline _LIBCPP_INLINE_VISIBILITY
1222constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1223 return __i == _Nx ? __not_found :
1224 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1225}
1226
1227template <class _T1, class ..._Args>
1228struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001229 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001230 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001231 static_assert(value != __not_found, "type not found in type list" );
1232 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001233};
1234
Eric Fiselier8087d302016-07-02 03:46:08 +00001235template <class _T1>
1236struct __find_exactly_one_checked<_T1> {
1237 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1238};
1239
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001240} // namespace __find_detail
Marshall Clow15b02e02013-07-13 02:54:05 +00001241
1242template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001243struct __find_exactly_one_t
1244 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1245};
Marshall Clow15b02e02013-07-13 02:54:05 +00001246
1247template <class _T1, class... _Args>
1248inline _LIBCPP_INLINE_VISIBILITY
1249constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1250{
1251 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1252}
1253
1254template <class _T1, class... _Args>
1255inline _LIBCPP_INLINE_VISIBILITY
1256constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1257{
1258 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1259}
1260
1261template <class _T1, class... _Args>
1262inline _LIBCPP_INLINE_VISIBILITY
1263constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1264{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001265 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001266}
1267
Eric Fiselier6dea8092015-12-18 00:36:55 +00001268template <class _T1, class... _Args>
1269inline _LIBCPP_INLINE_VISIBILITY
1270constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1271{
1272 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1273}
1274
Marshall Clow15b02e02013-07-13 02:54:05 +00001275#endif
1276
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277// tie
1278
1279template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001280inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001282tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283{
1284 return tuple<_Tp&...>(__t...);
1285}
1286
1287template <class _Up>
1288struct __ignore_t
1289{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001290 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001291 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1292 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293};
1294
Eric Fiselier24e70262017-02-06 01:25:31 +00001295namespace {
Louis Dionne559be102021-09-22 09:35:32 -04001296 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001297} // namespace
Howard Hinnantc51e1022010-05-11 19:42:16 +00001298
Howard Hinnantc51e1022010-05-11 19:42:16 +00001299template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001300inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001301tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001302make_tuple(_Tp&&... __t)
1303{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001304 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305}
1306
Howard Hinnant3d203a32010-08-19 18:59:38 +00001307template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001308inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1309tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001310forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001311{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001312 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001313}
1314
Howard Hinnantc834c512011-11-29 18:15:50 +00001315template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001316struct __tuple_equal
1317{
1318 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001319 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001320 bool operator()(const _Tp& __x, const _Up& __y)
1321 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001322 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323 }
1324};
1325
1326template <>
1327struct __tuple_equal<0>
1328{
1329 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001330 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001331 bool operator()(const _Tp&, const _Up&)
1332 {
1333 return true;
1334 }
1335};
1336
1337template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001338inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001339bool
1340operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1341{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001342 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001343 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1344}
1345
Arthur O'Dwyerfe74c902022-02-01 19:59:37 -05001346#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
Kent Ross0861b0d2021-10-08 14:54:28 -07001347
1348// operator<=>
1349
1350template <class ..._Tp, class ..._Up, size_t ..._Is>
1351_LIBCPP_HIDE_FROM_ABI constexpr
1352auto
1353__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1354 common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1355 static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1356 return __result;
1357}
1358
1359template <class ..._Tp, class ..._Up>
1360requires (sizeof...(_Tp) == sizeof...(_Up))
1361_LIBCPP_HIDE_FROM_ABI constexpr
1362common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1363operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1364{
1365 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1366}
1367
Arthur O'Dwyerfe74c902022-02-01 19:59:37 -05001368#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
Kent Ross0861b0d2021-10-08 14:54:28 -07001369
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001371inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001372bool
1373operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1374{
1375 return !(__x == __y);
1376}
1377
Howard Hinnantc834c512011-11-29 18:15:50 +00001378template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379struct __tuple_less
1380{
1381 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001382 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001383 bool operator()(const _Tp& __x, const _Up& __y)
1384 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001385 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1386 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1387 return true;
1388 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1389 return false;
1390 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001391 }
1392};
1393
1394template <>
1395struct __tuple_less<0>
1396{
1397 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001398 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399 bool operator()(const _Tp&, const _Up&)
1400 {
1401 return false;
1402 }
1403};
1404
1405template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001406inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001407bool
1408operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1409{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001410 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
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 __y < __x;
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 !(__x < __y);
1428}
1429
1430template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001431inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432bool
1433operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1434{
1435 return !(__y < __x);
1436}
1437
Arthur O'Dwyerfe74c902022-02-01 19:59:37 -05001438#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
Kent Ross0861b0d2021-10-08 14:54:28 -07001439
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440// tuple_cat
1441
Howard Hinnant6256ee72010-12-11 20:47:50 +00001442template <class _Tp, class _Up> struct __tuple_cat_type;
1443
1444template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001445struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001447 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001448};
1449
1450template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1451struct __tuple_cat_return_1
1452{
1453};
1454
1455template <class ..._Types, class _Tuple0>
1456struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1457{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001458 typedef _LIBCPP_NODEBUG typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001459 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001460 type;
1461};
1462
1463template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1464struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1465 : public __tuple_cat_return_1<
1466 typename __tuple_cat_type<
1467 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001468 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001469 >::type,
1470 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1471 _Tuple1, _Tuples...>
1472{
1473};
1474
1475template <class ..._Tuples> struct __tuple_cat_return;
1476
1477template <class _Tuple0, class ..._Tuples>
1478struct __tuple_cat_return<_Tuple0, _Tuples...>
1479 : public __tuple_cat_return_1<tuple<>,
1480 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1481 _Tuples...>
1482{
1483};
1484
1485template <>
1486struct __tuple_cat_return<>
1487{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001488 typedef _LIBCPP_NODEBUG tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001489};
1490
Marshall Clow2229cee2013-07-22 16:02:19 +00001491inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001492tuple<>
1493tuple_cat()
1494{
1495 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001496}
1497
Howard Hinnantc834c512011-11-29 18:15:50 +00001498template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001499struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500
Howard Hinnant21376f62010-12-12 23:04:37 +00001501template <class ..._Types, size_t ..._I0, class _Tuple0>
1502struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001503{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001504 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001505 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1506 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1507};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508
Howard Hinnant21376f62010-12-12 23:04:37 +00001509template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1510struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1511 _Tuple0, _Tuple1, _Tuples...>
1512 : public __tuple_cat_return_ref_imp<
1513 tuple<_Types..., typename __apply_cv<_Tuple0,
1514 typename tuple_element<_I0,
1515 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1516 typename __make_tuple_indices<tuple_size<typename
1517 remove_reference<_Tuple1>::type>::value>::type,
1518 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001519{
Howard Hinnant21376f62010-12-12 23:04:37 +00001520};
1521
1522template <class _Tuple0, class ..._Tuples>
1523struct __tuple_cat_return_ref
1524 : public __tuple_cat_return_ref_imp<tuple<>,
1525 typename __make_tuple_indices<
1526 tuple_size<typename remove_reference<_Tuple0>::type>::value
1527 >::type, _Tuple0, _Tuples...>
1528{
1529};
1530
1531template <class _Types, class _I0, class _J0>
1532struct __tuple_cat;
1533
1534template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001535struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001536{
1537 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001538 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001539 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1540 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1541 {
David Blaikie699a5e22019-10-28 18:03:59 -07001542 return _VSTD::forward_as_tuple(
1543 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1544 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001545 }
1546
1547 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001548 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001549 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1550 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1551 {
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001552 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1553 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001554 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001555 tuple<_Types...,
1556 typename __apply_cv<_Tuple0, typename tuple_element<
1557 _J0, _T0>::type>::type&&...>,
1558 typename __make_tuple_indices<sizeof...(_Types) +
1559 tuple_size<_T0>::value>::type,
1560 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1561 _VSTD::forward_as_tuple(
1562 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1563 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1564 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001565 }
1566};
1567
1568template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001569inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001570typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1571tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1572{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001573 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001574 return __tuple_cat<tuple<>, __tuple_indices<>,
1575 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001576 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1577 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578}
1579
1580template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001581struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582 : true_type {};
1583
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584template <class _T1, class _T2>
1585template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001586inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587pair<_T1, _T2>::pair(piecewise_construct_t,
1588 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1589 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001590 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1591 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592{
1593}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001594
Eric Fiselier8e892c52016-07-18 00:35:56 +00001595#if _LIBCPP_STD_VER > 14
1596template <class _Tp>
Louis Dionne559be102021-09-22 09:35:32 -04001597inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001598
1599#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1600
1601template <class _Fn, class _Tuple, size_t ..._Id>
1602inline _LIBCPP_INLINE_VISIBILITY
1603constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1604 __tuple_indices<_Id...>)
1605_LIBCPP_NOEXCEPT_RETURN(
1606 _VSTD::__invoke_constexpr(
1607 _VSTD::forward<_Fn>(__f),
1608 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1609)
1610
1611template <class _Fn, class _Tuple>
1612inline _LIBCPP_INLINE_VISIBILITY
1613constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1614_LIBCPP_NOEXCEPT_RETURN(
1615 _VSTD::__apply_tuple_impl(
1616 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001617 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001618)
1619
1620template <class _Tp, class _Tuple, size_t... _Idx>
1621inline _LIBCPP_INLINE_VISIBILITY
1622constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1623_LIBCPP_NOEXCEPT_RETURN(
1624 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1625)
1626
1627template <class _Tp, class _Tuple>
1628inline _LIBCPP_INLINE_VISIBILITY
1629constexpr _Tp make_from_tuple(_Tuple&& __t)
1630_LIBCPP_NOEXCEPT_RETURN(
1631 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001632 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001633)
1634
1635#undef _LIBCPP_NOEXCEPT_RETURN
1636
1637#endif // _LIBCPP_STD_VER > 14
1638
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001639#endif // !defined(_LIBCPP_CXX03_LANG)
1640
Howard Hinnantc51e1022010-05-11 19:42:16 +00001641_LIBCPP_END_NAMESPACE_STD
1642
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001643#endif // _LIBCPP_TUPLE