blob: b5989dd7b04094187975ccb99812e58278f6ad43 [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 <__functional_base>
173#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>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400179#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000182#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000183#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000185#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000187#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188
189_LIBCPP_BEGIN_NAMESPACE_STD
190
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000191#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192
Marshall Clowf50d66f2014-03-03 06:18:11 +0000193
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194// __tuple_leaf
195
Eric Fiselierf7394302015-06-13 07:08:02 +0000196template <size_t _Ip, class _Hp,
197 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000198 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000199class __tuple_leaf;
200
201template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500202inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000204 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205{
206 swap(__x.get(), __y.get());
207}
208
209template <size_t _Ip, class _Hp, bool>
210class __tuple_leaf
211{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000212 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213
Eric Fiselierca8bba12016-07-20 02:57:39 +0000214 template <class _Tp>
215 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000216#if __has_keyword(__reference_binds_to_temporary)
217 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000218#else
219 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000220#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000221 }
222
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500223 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224 __tuple_leaf& operator=(const __tuple_leaf&);
225public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500226 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000227 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228 {static_assert(!is_reference<_Hp>::value,
229 "Attempted to default construct a reference element in a tuple");}
230
231 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500232 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000234 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235 {static_assert(!is_reference<_Hp>::value,
236 "Attempted to default construct a reference element in a tuple");}
237
238 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500239 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000241 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242 {static_assert(!is_reference<_Hp>::value,
243 "Attempted to default construct a reference element in a tuple");}
244
245 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500246 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000248 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249 {static_assert(!is_reference<_Hp>::value,
250 "Attempted to default construct a reference element in a tuple");}
251
Howard Hinnant693fc212010-09-27 17:54:17 +0000252 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400253 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000254 _And<
255 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
256 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000257 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000258 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000259 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000260 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000261 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000262 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000263 {static_assert(__can_bind_reference<_Tp&&>(),
264 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000265
266 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500267 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000269 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000270 {static_assert(__can_bind_reference<_Tp&&>(),
271 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272
273 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500274 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000276 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000277 {static_assert(!is_reference<_Hp>::value,
278 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279
280 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500281 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000283 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000284 {static_assert(!is_reference<_Hp>::value,
285 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286
Marshall Clow47fcee52014-04-21 23:48:09 +0000287 __tuple_leaf(const __tuple_leaf& __t) = default;
288 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500290 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000291 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000293 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294 return 0;
295 }
296
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000297 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
298 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000299};
300
301template <size_t _Ip, class _Hp>
302class __tuple_leaf<_Ip, _Hp, true>
303 : private _Hp
304{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500305 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000306 __tuple_leaf& operator=(const __tuple_leaf&);
307public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500308 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000309 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000310
311 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500312 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000313 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
314
315 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500316 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
318 : _Hp(allocator_arg_t(), __a) {}
319
320 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500321 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000322 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
323 : _Hp(__a) {}
324
Howard Hinnant693fc212010-09-27 17:54:17 +0000325 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400326 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000327 _And<
328 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
329 is_constructible<_Hp, _Tp>
330 >::value
331 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000332 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000333 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000334 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000335 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336
337 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500338 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000340 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341
342 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500343 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000345 : _Hp(allocator_arg_t(), __a, _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, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000350 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000352 __tuple_leaf(__tuple_leaf const &) = default;
353 __tuple_leaf(__tuple_leaf &&) = default;
354
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500355 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000356 int
357 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000359 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360 return 0;
361 }
362
Marshall Clow2229cee2013-07-22 16:02:19 +0000363 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
364 _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 +0000365};
366
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000367template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500368_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000369void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370
Marshall Clowc470eae2014-10-15 10:33:02 +0000371template <class _Tp>
372struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000373
Marshall Clowc470eae2014-10-15 10:33:02 +0000374template <class ..._Tp>
375struct __all_default_constructible<__tuple_types<_Tp...>>
376 : __all<is_default_constructible<_Tp>::value...>
377{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000378
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379// __tuple_impl
380
381template<class _Indx, class ..._Tp> struct __tuple_impl;
382
383template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000384struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385 : public __tuple_leaf<_Indx, _Tp>...
386{
Howard Hinnant38469632012-07-06 20:39:45 +0000387 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500388 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000389 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000390
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391 template <size_t ..._Uf, class ..._Tf,
392 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000393 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394 explicit
395 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
396 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000397 _Up&&... __u)
398 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
399 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000400 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401 __tuple_leaf<_Ul, _Tl>()...
402 {}
403
404 template <class _Alloc, size_t ..._Uf, class ..._Tf,
405 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500406 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407 explicit
408 __tuple_impl(allocator_arg_t, const _Alloc& __a,
409 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
410 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
411 _Up&&... __u) :
412 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000413 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000414 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
415 {}
416
417 template <class _Tuple,
418 class = typename enable_if
419 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000420 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421 >::type
422 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000423 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000424 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
425 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000426 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
427 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 {}
429
430 template <class _Alloc, class _Tuple,
431 class = typename enable_if
432 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000433 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434 >::type
435 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500436 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000437 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
438 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000439 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000440 _VSTD::forward<typename tuple_element<_Indx,
441 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442 {}
443
Howard Hinnant0d032d12013-11-06 17:45:43 +0000444 __tuple_impl(const __tuple_impl&) = default;
445 __tuple_impl(__tuple_impl&&) = default;
446
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500447 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000449 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400451 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452 }
453};
454
Louis Dionne6c0d5342018-07-31 11:56:20 -0400455template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500456_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400457void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
458 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
459}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000460
Louis Dionne6c0d5342018-07-31 11:56:20 -0400461template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500462_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400463void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
464 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500465 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400466 ), void(), 0)...);
467}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000468
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000470class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000472 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000474 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475
Marshall Clow0abb1042013-07-17 18:25:36 +0000476 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000477 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
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 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const 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 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000482 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
483 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500485 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486
Louis Dionne574e2e32021-02-10 16:19:50 -0500487 // tuple() constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400488 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500489 _And<
490 _IsImpDefault<_Tp>... // explicit check
491 >::value
492 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400493 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000494 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500495 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
496 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000497
Louis Dionne574e2e32021-02-10 16:19:50 -0500498 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400499 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500500 _And<
501 _IsDefault<_Tp>...,
502 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
503 >::value
504 , int> = 0>
505 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
506 explicit tuple()
507 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
508 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000509
Louis Dionne9ce598d2021-09-08 09:14:43 -0400510 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500511 _And<
512 _IsImpDefault<_Tp>... // explicit check
513 >::value
514 , int> = 0>
515 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
516 tuple(allocator_arg_t, _Alloc const& __a)
517 : __base_(allocator_arg_t(), __a,
518 __tuple_indices<>(), __tuple_types<>(),
519 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
520 __tuple_types<_Tp...>()) {}
521
522 template <class _Alloc,
523 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400524 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500525 _And<
526 _IsDefault<_Tp>...,
527 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
528 >::value
529 , int> = 0>
530 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
531 explicit tuple(allocator_arg_t, _Alloc const& __a)
532 : __base_(allocator_arg_t(), __a,
533 __tuple_indices<>(), __tuple_types<>(),
534 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
535 __tuple_types<_Tp...>()) {}
536
537 // tuple(const T&...) constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400538 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500539 _And<
540 _BoolConstant<sizeof...(_Tp) >= 1>,
541 is_copy_constructible<_Tp>...,
542 is_convertible<const _Tp&, _Tp>... // explicit check
543 >::value
544 , int> = 0>
545 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
546 tuple(const _Tp& ... __t)
547 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
548 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
549 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
550 typename __make_tuple_indices<0>::type(),
551 typename __make_tuple_types<tuple, 0>::type(),
552 __t...
553 ) {}
554
Louis Dionne9ce598d2021-09-08 09:14:43 -0400555 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500556 _And<
557 _BoolConstant<sizeof...(_Tp) >= 1>,
558 is_copy_constructible<_Tp>...,
559 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
560 >::value
561 , int> = 0>
562 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
563 explicit tuple(const _Tp& ... __t)
564 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
565 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
566 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
567 typename __make_tuple_indices<0>::type(),
568 typename __make_tuple_types<tuple, 0>::type(),
569 __t...
570 ) {}
571
Louis Dionne9ce598d2021-09-08 09:14:43 -0400572 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500573 _And<
574 _BoolConstant<sizeof...(_Tp) >= 1>,
575 is_copy_constructible<_Tp>...,
576 is_convertible<const _Tp&, _Tp>... // explicit check
577 >::value
578 , int> = 0>
579 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
580 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
581 : __base_(allocator_arg_t(), __a,
582 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
583 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
584 typename __make_tuple_indices<0>::type(),
585 typename __make_tuple_types<tuple, 0>::type(),
586 __t...
587 ) {}
588
Louis Dionne9ce598d2021-09-08 09:14:43 -0400589 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500590 _And<
591 _BoolConstant<sizeof...(_Tp) >= 1>,
592 is_copy_constructible<_Tp>...,
593 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
594 >::value
595 , int> = 0>
596 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
597 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
598 : __base_(allocator_arg_t(), __a,
599 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
600 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
601 typename __make_tuple_indices<0>::type(),
602 typename __make_tuple_types<tuple, 0>::type(),
603 __t...
604 ) {}
605
606 // tuple(U&& ...) constructors (including allocator_arg_t variants)
607 template <class ..._Up> struct _IsThisTuple : false_type { };
608 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
609
610 template <class ..._Up>
611 struct _EnableUTypesCtor : _And<
612 _BoolConstant<sizeof...(_Tp) >= 1>,
613 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
614 is_constructible<_Tp, _Up>...
615 > { };
616
Louis Dionne9ce598d2021-09-08 09:14:43 -0400617 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500618 _And<
619 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
620 _EnableUTypesCtor<_Up...>,
621 is_convertible<_Up, _Tp>... // explicit check
622 >::value
623 , int> = 0>
624 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
625 tuple(_Up&&... __u)
626 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
627 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
628 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
629 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
630 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
631 _VSTD::forward<_Up>(__u)...) {}
632
Louis Dionne9ce598d2021-09-08 09:14:43 -0400633 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500634 _And<
635 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
636 _EnableUTypesCtor<_Up...>,
637 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
638 >::value
639 , int> = 0>
640 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
641 explicit tuple(_Up&&... __u)
642 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
643 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
644 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
645 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
646 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
647 _VSTD::forward<_Up>(__u)...) {}
648
Louis Dionne9ce598d2021-09-08 09:14:43 -0400649 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500650 _And<
651 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
652 _EnableUTypesCtor<_Up...>,
653 is_convertible<_Up, _Tp>... // explicit check
654 >::value
655 , int> = 0>
656 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
657 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
658 : __base_(allocator_arg_t(), __a,
659 typename __make_tuple_indices<sizeof...(_Up)>::type(),
660 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
661 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
662 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
663 _VSTD::forward<_Up>(__u)...) {}
664
Louis Dionne9ce598d2021-09-08 09:14:43 -0400665 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500666 _And<
667 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
668 _EnableUTypesCtor<_Up...>,
669 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
670 >::value
671 , int> = 0>
672 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
673 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
674 : __base_(allocator_arg_t(), __a,
675 typename __make_tuple_indices<sizeof...(_Up)>::type(),
676 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
677 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
678 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
679 _VSTD::forward<_Up>(__u)...) {}
680
681 // Copy and move constructors (including the allocator_arg_t variants)
682 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000683 tuple(tuple&&) = default;
684
Louis Dionne9ce598d2021-09-08 09:14:43 -0400685 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500686 _And<is_copy_constructible<_Tp>...>::value
687 , int> = 0>
688 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
689 : __base_(allocator_arg_t(), __alloc, __t)
690 { }
691
Louis Dionne9ce598d2021-09-08 09:14:43 -0400692 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500693 _And<is_move_constructible<_Tp>...>::value
694 , int> = 0>
695 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
696 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
697 { }
698
699 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
700 template <class ..._Up>
701 struct _EnableCopyFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400702 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
703 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500704 _BoolConstant<sizeof...(_Tp) != 1>,
705 // _Tp and _Up are 1-element packs - the pack expansions look
706 // weird to avoid tripping up the type traits in degenerate cases
707 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500708 _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
709 _Not<is_constructible<_Tp, const tuple<_Up>&> >...
710 >
711 >,
712 is_constructible<_Tp, const _Up&>...
713 > { };
714
Louis Dionne9ce598d2021-09-08 09:14:43 -0400715 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500716 _And<
717 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
718 _EnableCopyFromOtherTuple<_Up...>,
719 is_convertible<const _Up&, _Tp>... // explicit check
720 >::value
721 , int> = 0>
722 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
723 tuple(const tuple<_Up...>& __t)
724 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
725 : __base_(__t)
726 { }
727
Louis Dionne9ce598d2021-09-08 09:14:43 -0400728 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500729 _And<
730 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
731 _EnableCopyFromOtherTuple<_Up...>,
732 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
733 >::value
734 , int> = 0>
735 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
736 explicit tuple(const tuple<_Up...>& __t)
737 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
738 : __base_(__t)
739 { }
740
Louis Dionne9ce598d2021-09-08 09:14:43 -0400741 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500742 _And<
743 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
744 _EnableCopyFromOtherTuple<_Up...>,
745 is_convertible<const _Up&, _Tp>... // explicit check
746 >::value
747 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500748 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500749 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
750 : __base_(allocator_arg_t(), __a, __t)
751 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000752
Louis Dionne9ce598d2021-09-08 09:14:43 -0400753 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500754 _And<
755 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
756 _EnableCopyFromOtherTuple<_Up...>,
757 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
758 >::value
759 , int> = 0>
760 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
761 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
762 : __base_(allocator_arg_t(), __a, __t)
763 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000764
Louis Dionne574e2e32021-02-10 16:19:50 -0500765 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
766 template <class ..._Up>
767 struct _EnableMoveFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400768 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
769 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500770 _BoolConstant<sizeof...(_Tp) != 1>,
771 // _Tp and _Up are 1-element packs - the pack expansions look
772 // weird to avoid tripping up the type traits in degenerate cases
773 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500774 _Not<is_convertible<tuple<_Up>, _Tp> >...,
775 _Not<is_constructible<_Tp, tuple<_Up> > >...
776 >
777 >,
778 is_constructible<_Tp, _Up>...
779 > { };
780
Louis Dionne9ce598d2021-09-08 09:14:43 -0400781 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500782 _And<
783 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
784 _EnableMoveFromOtherTuple<_Up...>,
785 is_convertible<_Up, _Tp>... // explicit check
786 >::value
787 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000788 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500789 tuple(tuple<_Up...>&& __t)
790 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
791 : __base_(_VSTD::move(__t))
792 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793
Louis Dionne9ce598d2021-09-08 09:14:43 -0400794 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500795 _And<
796 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
797 _EnableMoveFromOtherTuple<_Up...>,
798 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
799 >::value
800 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000801 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500802 explicit tuple(tuple<_Up...>&& __t)
803 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
804 : __base_(_VSTD::move(__t))
805 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000806
Louis Dionne9ce598d2021-09-08 09:14:43 -0400807 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500808 _And<
809 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
810 _EnableMoveFromOtherTuple<_Up...>,
811 is_convertible<_Up, _Tp>... // explicit check
812 >::value
813 , int> = 0>
814 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
815 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
816 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
817 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818
Louis Dionne9ce598d2021-09-08 09:14:43 -0400819 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500820 _And<
821 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
822 _EnableMoveFromOtherTuple<_Up...>,
823 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
824 >::value
825 , int> = 0>
826 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
827 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
828 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
829 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000830
Louis Dionne574e2e32021-02-10 16:19:50 -0500831 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
832 template <class _Up1, class _Up2, class ..._DependentTp>
833 struct _EnableImplicitCopyFromPair : _And<
834 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
835 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
836 is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
837 is_convertible<const _Up2&, _SecondType<_DependentTp...> >
838 > { };
Howard Hinnant65704d02012-04-01 23:10:42 +0000839
Louis Dionne574e2e32021-02-10 16:19:50 -0500840 template <class _Up1, class _Up2, class ..._DependentTp>
841 struct _EnableExplicitCopyFromPair : _And<
842 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
843 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
844 _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
845 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
846 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847
Louis Dionne9ce598d2021-09-08 09:14:43 -0400848 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500849 _And<
850 _BoolConstant<sizeof...(_Tp) == 2>,
851 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
852 >::value
853 , int> = 0>
854 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
855 tuple(const pair<_Up1, _Up2>& __p)
856 _NOEXCEPT_((_And<
857 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
858 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
859 >::value))
860 : __base_(__p)
861 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000862
Louis Dionne9ce598d2021-09-08 09:14:43 -0400863 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500864 _And<
865 _BoolConstant<sizeof...(_Tp) == 2>,
866 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
867 >::value
868 , int> = 0>
869 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
870 explicit tuple(const pair<_Up1, _Up2>& __p)
871 _NOEXCEPT_((_And<
872 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
873 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
874 >::value))
875 : __base_(__p)
876 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000877
Louis Dionne9ce598d2021-09-08 09:14:43 -0400878 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500879 _And<
880 _BoolConstant<sizeof...(_Tp) == 2>,
881 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
882 >::value
883 , int> = 0>
884 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
885 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
886 : __base_(allocator_arg_t(), __a, __p)
887 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888
Louis Dionne9ce598d2021-09-08 09:14:43 -0400889 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500890 _And<
891 _BoolConstant<sizeof...(_Tp) == 2>,
892 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
893 >::value
894 , int> = 0>
895 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
896 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
897 : __base_(allocator_arg_t(), __a, __p)
898 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000899
Louis Dionne574e2e32021-02-10 16:19:50 -0500900 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
901 template <class _Up1, class _Up2, class ..._DependentTp>
902 struct _EnableImplicitMoveFromPair : _And<
903 is_constructible<_FirstType<_DependentTp...>, _Up1>,
904 is_constructible<_SecondType<_DependentTp...>, _Up2>,
905 is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
906 is_convertible<_Up2, _SecondType<_DependentTp...> >
907 > { };
Eric Fiselierec5a2102019-07-12 23:01:48 +0000908
Louis Dionne574e2e32021-02-10 16:19:50 -0500909 template <class _Up1, class _Up2, class ..._DependentTp>
910 struct _EnableExplicitMoveFromPair : _And<
911 is_constructible<_FirstType<_DependentTp...>, _Up1>,
912 is_constructible<_SecondType<_DependentTp...>, _Up2>,
913 _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
914 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
915 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916
Louis Dionne9ce598d2021-09-08 09:14:43 -0400917 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500918 _And<
919 _BoolConstant<sizeof...(_Tp) == 2>,
920 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
921 >::value
922 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400923 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500924 tuple(pair<_Up1, _Up2>&& __p)
925 _NOEXCEPT_((_And<
926 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
927 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
928 >::value))
929 : __base_(_VSTD::move(__p))
930 { }
931
Louis Dionne9ce598d2021-09-08 09:14:43 -0400932 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500933 _And<
934 _BoolConstant<sizeof...(_Tp) == 2>,
935 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
936 >::value
937 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400938 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500939 explicit tuple(pair<_Up1, _Up2>&& __p)
940 _NOEXCEPT_((_And<
941 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
942 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
943 >::value))
944 : __base_(_VSTD::move(__p))
945 { }
946
Louis Dionne9ce598d2021-09-08 09:14:43 -0400947 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500948 _And<
949 _BoolConstant<sizeof...(_Tp) == 2>,
950 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
951 >::value
952 , int> = 0>
953 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
954 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
955 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
956 { }
957
Louis Dionne9ce598d2021-09-08 09:14:43 -0400958 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500959 _And<
960 _BoolConstant<sizeof...(_Tp) == 2>,
961 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
962 >::value
963 , int> = 0>
964 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
965 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
966 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
967 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000968
Louis Dionne6c0d5342018-07-31 11:56:20 -0400969 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500970 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400971 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
972 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000973 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400974 _VSTD::__memberwise_copy_assign(*this, __tuple,
975 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000976 return *this;
977 }
978
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500979 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400980 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
981 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000982 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400983 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
984 __tuple_types<_Tp...>(),
985 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000986 return *this;
987 }
988
Louis Dionne9ce598d2021-09-08 09:14:43 -0400989 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -0400990 _And<
991 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
992 is_assignable<_Tp&, _Up const&>...
993 >::value
994 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500995 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400996 tuple& operator=(tuple<_Up...> const& __tuple)
997 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
998 {
999 _VSTD::__memberwise_copy_assign(*this, __tuple,
1000 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1001 return *this;
1002 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003
Louis Dionne9ce598d2021-09-08 09:14:43 -04001004 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001005 _And<
1006 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1007 is_assignable<_Tp&, _Up>...
1008 >::value
1009 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001010 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001011 tuple& operator=(tuple<_Up...>&& __tuple)
1012 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1013 {
1014 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1015 __tuple_types<_Up...>(),
1016 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1017 return *this;
1018 }
1019
Louis Dionne9ce598d2021-09-08 09:14:43 -04001020 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001021 _And<_Dep,
1022 _BoolConstant<sizeof...(_Tp) == 2>,
1023 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1024 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1025 >::value
1026 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001027 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001028 tuple& operator=(pair<_Up1, _Up2> const& __pair)
1029 _NOEXCEPT_((_And<
1030 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1031 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1032 >::value))
1033 {
1034 _VSTD::get<0>(*this) = __pair.first;
1035 _VSTD::get<1>(*this) = __pair.second;
1036 return *this;
1037 }
1038
Louis Dionne9ce598d2021-09-08 09:14:43 -04001039 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001040 _And<_Dep,
1041 _BoolConstant<sizeof...(_Tp) == 2>,
1042 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1043 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1044 >::value
1045 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001046 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001047 tuple& operator=(pair<_Up1, _Up2>&& __pair)
1048 _NOEXCEPT_((_And<
1049 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1050 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1051 >::value))
1052 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001053 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1054 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001055 return *this;
1056 }
1057
1058 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001059 template<class _Up, size_t _Np, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001060 _And<
1061 _BoolConstant<_Np == sizeof...(_Tp)>,
1062 is_assignable<_Tp&, _Up const&>...
1063 >::value
1064 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001065 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001066 tuple& operator=(array<_Up, _Np> const& __array)
1067 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1068 {
1069 _VSTD::__memberwise_copy_assign(*this, __array,
1070 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1071 return *this;
1072 }
1073
1074 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001075 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001076 _And<
1077 _BoolConstant<_Np == sizeof...(_Tp)>,
1078 is_assignable<_Tp&, _Up>...
1079 >::value
1080 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001081 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001082 tuple& operator=(array<_Up, _Np>&& __array)
1083 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1084 {
1085 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1086 __tuple_types<_If<true, _Up, _Tp>...>(),
1087 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1088 return *this;
1089 }
1090
1091 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001092 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001093 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001094 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001095};
1096
1097template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001098class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099{
1100public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001101 _LIBCPP_INLINE_VISIBILITY constexpr
1102 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001104 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001105 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001106 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001107 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001108 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001109 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001110 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001111 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001112 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001113 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001114 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001115 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001116 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001117};
1118
Arthur O'Dwyer73541c72022-02-02 11:19:46 -05001119#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001120template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1121 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1122struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1123 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1124};
1125
1126template <class... _TTypes, class... _UTypes>
1127 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1128struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1129 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1130};
Arthur O'Dwyer73541c72022-02-02 11:19:46 -05001131#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001132
1133#if _LIBCPP_STD_VER > 14
Louis Dionne616da2a2019-08-12 18:30:31 +00001134template <class ..._Tp>
1135tuple(_Tp...) -> tuple<_Tp...>;
1136template <class _Tp1, class _Tp2>
1137tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1138template <class _Alloc, class ..._Tp>
1139tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1140template <class _Alloc, class _Tp1, class _Tp2>
1141tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1142template <class _Alloc, class ..._Tp>
1143tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001144#endif
1145
Howard Hinnantc51e1022010-05-11 19:42:16 +00001146template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001147inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001148typename enable_if
1149<
1150 __all<__is_swappable<_Tp>::value...>::value,
1151 void
1152>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001153swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1154 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1155 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156
1157// get
1158
1159template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001160inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001161typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001162get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001163{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001164 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001165 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166}
1167
1168template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001169inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001170const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001171get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001173 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001174 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175}
1176
Howard Hinnant22e97242010-11-17 19:52:17 +00001177template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001178inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001179typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001180get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001181{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001182 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001183 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001184 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001185}
1186
Eric Fiselier6dea8092015-12-18 00:36:55 +00001187template <size_t _Ip, class ..._Tp>
1188inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1189const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1190get(const tuple<_Tp...>&& __t) _NOEXCEPT
1191{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001192 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001193 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001194 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001195}
1196
Marshall Clow15b02e02013-07-13 02:54:05 +00001197#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001198
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001199namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001200
Louis Dionne7dd28aa2021-07-20 11:46:05 -04001201static constexpr size_t __not_found = static_cast<size_t>(-1);
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001202static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001203
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001204inline _LIBCPP_INLINE_VISIBILITY
1205constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1206 return !__matches ? __res :
1207 (__res == __not_found ? __curr_i : __ambiguous);
1208}
Marshall Clow15b02e02013-07-13 02:54:05 +00001209
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001210template <size_t _Nx>
1211inline _LIBCPP_INLINE_VISIBILITY
1212constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1213 return __i == _Nx ? __not_found :
1214 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1215}
1216
1217template <class _T1, class ..._Args>
1218struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001219 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001220 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001221 static_assert(value != __not_found, "type not found in type list" );
1222 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001223};
1224
Eric Fiselier8087d302016-07-02 03:46:08 +00001225template <class _T1>
1226struct __find_exactly_one_checked<_T1> {
1227 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1228};
1229
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001230} // namespace __find_detail
Marshall Clow15b02e02013-07-13 02:54:05 +00001231
1232template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001233struct __find_exactly_one_t
1234 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1235};
Marshall Clow15b02e02013-07-13 02:54:05 +00001236
1237template <class _T1, class... _Args>
1238inline _LIBCPP_INLINE_VISIBILITY
1239constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1240{
1241 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1242}
1243
1244template <class _T1, class... _Args>
1245inline _LIBCPP_INLINE_VISIBILITY
1246constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1247{
1248 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1249}
1250
1251template <class _T1, class... _Args>
1252inline _LIBCPP_INLINE_VISIBILITY
1253constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1254{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001255 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001256}
1257
Eric Fiselier6dea8092015-12-18 00:36:55 +00001258template <class _T1, class... _Args>
1259inline _LIBCPP_INLINE_VISIBILITY
1260constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1261{
1262 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1263}
1264
Marshall Clow15b02e02013-07-13 02:54:05 +00001265#endif
1266
Howard Hinnantc51e1022010-05-11 19:42:16 +00001267// tie
1268
1269template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001270inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001271tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001272tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001273{
1274 return tuple<_Tp&...>(__t...);
1275}
1276
1277template <class _Up>
1278struct __ignore_t
1279{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001281 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1282 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283};
1284
Eric Fiselier24e70262017-02-06 01:25:31 +00001285namespace {
Louis Dionne559be102021-09-22 09:35:32 -04001286 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001287} // namespace
Howard Hinnantc51e1022010-05-11 19:42:16 +00001288
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001290inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001291tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292make_tuple(_Tp&&... __t)
1293{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001294 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001295}
1296
Howard Hinnant3d203a32010-08-19 18:59:38 +00001297template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001298inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1299tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001300forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001301{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001302 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001303}
1304
Howard Hinnantc834c512011-11-29 18:15:50 +00001305template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001306struct __tuple_equal
1307{
1308 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001309 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310 bool operator()(const _Tp& __x, const _Up& __y)
1311 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001312 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313 }
1314};
1315
1316template <>
1317struct __tuple_equal<0>
1318{
1319 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001320 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321 bool operator()(const _Tp&, const _Up&)
1322 {
1323 return true;
1324 }
1325};
1326
1327template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001328inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329bool
1330operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1331{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001332 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001333 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1334}
1335
Arthur O'Dwyerfe74c902022-02-01 19:59:37 -05001336#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
Kent Ross0861b0d2021-10-08 14:54:28 -07001337
1338// operator<=>
1339
1340template <class ..._Tp, class ..._Up, size_t ..._Is>
1341_LIBCPP_HIDE_FROM_ABI constexpr
1342auto
1343__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1344 common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1345 static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1346 return __result;
1347}
1348
1349template <class ..._Tp, class ..._Up>
1350requires (sizeof...(_Tp) == sizeof...(_Up))
1351_LIBCPP_HIDE_FROM_ABI constexpr
1352common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1353operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1354{
1355 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1356}
1357
Arthur O'Dwyerfe74c902022-02-01 19:59:37 -05001358#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)
Kent Ross0861b0d2021-10-08 14:54:28 -07001359
Howard Hinnantc51e1022010-05-11 19:42:16 +00001360template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001361inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001362bool
1363operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1364{
1365 return !(__x == __y);
1366}
1367
Howard Hinnantc834c512011-11-29 18:15:50 +00001368template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369struct __tuple_less
1370{
1371 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001372 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373 bool operator()(const _Tp& __x, const _Up& __y)
1374 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001375 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1376 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1377 return true;
1378 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1379 return false;
1380 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381 }
1382};
1383
1384template <>
1385struct __tuple_less<0>
1386{
1387 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001388 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389 bool operator()(const _Tp&, const _Up&)
1390 {
1391 return false;
1392 }
1393};
1394
1395template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001396inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397bool
1398operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1399{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001400 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001401 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1402}
1403
1404template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001405inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001406bool
1407operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1408{
1409 return __y < __x;
1410}
1411
1412template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001413inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414bool
1415operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1416{
1417 return !(__x < __y);
1418}
1419
1420template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001421inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001422bool
1423operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1424{
1425 return !(__y < __x);
1426}
1427
Arthur O'Dwyerfe74c902022-02-01 19:59:37 -05001428#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
Kent Ross0861b0d2021-10-08 14:54:28 -07001429
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430// tuple_cat
1431
Howard Hinnant6256ee72010-12-11 20:47:50 +00001432template <class _Tp, class _Up> struct __tuple_cat_type;
1433
1434template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001435struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001436{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001437 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001438};
1439
1440template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1441struct __tuple_cat_return_1
1442{
1443};
1444
1445template <class ..._Types, class _Tuple0>
1446struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1447{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001448 typedef _LIBCPP_NODEBUG typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001449 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001450 type;
1451};
1452
1453template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1454struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1455 : public __tuple_cat_return_1<
1456 typename __tuple_cat_type<
1457 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001458 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001459 >::type,
1460 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1461 _Tuple1, _Tuples...>
1462{
1463};
1464
1465template <class ..._Tuples> struct __tuple_cat_return;
1466
1467template <class _Tuple0, class ..._Tuples>
1468struct __tuple_cat_return<_Tuple0, _Tuples...>
1469 : public __tuple_cat_return_1<tuple<>,
1470 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1471 _Tuples...>
1472{
1473};
1474
1475template <>
1476struct __tuple_cat_return<>
1477{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001478 typedef _LIBCPP_NODEBUG tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001479};
1480
Marshall Clow2229cee2013-07-22 16:02:19 +00001481inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001482tuple<>
1483tuple_cat()
1484{
1485 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486}
1487
Howard Hinnantc834c512011-11-29 18:15:50 +00001488template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001489struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001490
Howard Hinnant21376f62010-12-12 23:04:37 +00001491template <class ..._Types, size_t ..._I0, class _Tuple0>
1492struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001494 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001495 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1496 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1497};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498
Howard Hinnant21376f62010-12-12 23:04:37 +00001499template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1500struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1501 _Tuple0, _Tuple1, _Tuples...>
1502 : public __tuple_cat_return_ref_imp<
1503 tuple<_Types..., typename __apply_cv<_Tuple0,
1504 typename tuple_element<_I0,
1505 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1506 typename __make_tuple_indices<tuple_size<typename
1507 remove_reference<_Tuple1>::type>::value>::type,
1508 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509{
Howard Hinnant21376f62010-12-12 23:04:37 +00001510};
1511
1512template <class _Tuple0, class ..._Tuples>
1513struct __tuple_cat_return_ref
1514 : public __tuple_cat_return_ref_imp<tuple<>,
1515 typename __make_tuple_indices<
1516 tuple_size<typename remove_reference<_Tuple0>::type>::value
1517 >::type, _Tuple0, _Tuples...>
1518{
1519};
1520
1521template <class _Types, class _I0, class _J0>
1522struct __tuple_cat;
1523
1524template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001525struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001526{
1527 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001528 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001529 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1530 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1531 {
David Blaikie699a5e22019-10-28 18:03:59 -07001532 return _VSTD::forward_as_tuple(
1533 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1534 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001535 }
1536
1537 template <class _Tuple0, class _Tuple1, class ..._Tuples>
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&&, _Tuple1&&, _Tuples&&...>::type
1540 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1541 {
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001542 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1543 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001544 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001545 tuple<_Types...,
1546 typename __apply_cv<_Tuple0, typename tuple_element<
1547 _J0, _T0>::type>::type&&...>,
1548 typename __make_tuple_indices<sizeof...(_Types) +
1549 tuple_size<_T0>::value>::type,
1550 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1551 _VSTD::forward_as_tuple(
1552 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1553 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1554 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001555 }
1556};
1557
1558template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001559inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001560typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1561tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1562{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001563 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001564 return __tuple_cat<tuple<>, __tuple_indices<>,
1565 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001566 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1567 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568}
1569
1570template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001571struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001572 : true_type {};
1573
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574template <class _T1, class _T2>
1575template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001576inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577pair<_T1, _T2>::pair(piecewise_construct_t,
1578 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1579 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001580 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1581 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582{
1583}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584
Eric Fiselier8e892c52016-07-18 00:35:56 +00001585#if _LIBCPP_STD_VER > 14
1586template <class _Tp>
Louis Dionne559be102021-09-22 09:35:32 -04001587inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001588
1589#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1590
1591template <class _Fn, class _Tuple, size_t ..._Id>
1592inline _LIBCPP_INLINE_VISIBILITY
1593constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1594 __tuple_indices<_Id...>)
1595_LIBCPP_NOEXCEPT_RETURN(
1596 _VSTD::__invoke_constexpr(
1597 _VSTD::forward<_Fn>(__f),
1598 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1599)
1600
1601template <class _Fn, class _Tuple>
1602inline _LIBCPP_INLINE_VISIBILITY
1603constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1604_LIBCPP_NOEXCEPT_RETURN(
1605 _VSTD::__apply_tuple_impl(
1606 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001607 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001608)
1609
1610template <class _Tp, class _Tuple, size_t... _Idx>
1611inline _LIBCPP_INLINE_VISIBILITY
1612constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1613_LIBCPP_NOEXCEPT_RETURN(
1614 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1615)
1616
1617template <class _Tp, class _Tuple>
1618inline _LIBCPP_INLINE_VISIBILITY
1619constexpr _Tp make_from_tuple(_Tuple&& __t)
1620_LIBCPP_NOEXCEPT_RETURN(
1621 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001622 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001623)
1624
1625#undef _LIBCPP_NOEXCEPT_RETURN
1626
1627#endif // _LIBCPP_STD_VER > 14
1628
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001629#endif // !defined(_LIBCPP_CXX03_LANG)
1630
Howard Hinnantc51e1022010-05-11 19:42:16 +00001631_LIBCPP_END_NAMESPACE_STD
1632
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001633#endif // _LIBCPP_TUPLE