blob: 221eb23dd3f8d68b7aa673c8202996395b8ce88a [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;
Hui Xied1637a82022-05-12 13:23:11 +010028
29 template<class... UTypes>
30 constexpr explicit(see-below) tuple(tuple<UTypes...>&); // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000031 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000032 explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000033 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000034 explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
Hui Xied1637a82022-05-12 13:23:11 +010035 template<class... UTypes>
36 constexpr explicit(see-below) tuple(const tuple<UTypes...>&&); // C++23
37
38 template<class U1, class U2>
39 constexpr explicit(see-below) tuple(pair<U1, U2>&); // iff sizeof...(Types) == 2 // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000040 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000041 explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000043 explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
Hui Xied1637a82022-05-12 13:23:11 +010044 template<class U1, class U2>
45 constexpr explicit(see-below) tuple(const pair<U1, U2>&&); // iff sizeof...(Types) == 2 // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000046
47 // allocator-extended constructors
48 template <class Alloc>
49 tuple(allocator_arg_t, const Alloc& a);
50 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050051 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000052 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050053 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000054 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050055 tuple(allocator_arg_t, const Alloc& a, const tuple&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000056 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050057 tuple(allocator_arg_t, const Alloc& a, tuple&&); // constexpr in C++20
Hui Xied1637a82022-05-12 13:23:11 +010058 template<class Alloc, class... UTypes>
59 constexpr explicit(see-below)
Louis Dionne76450ee2022-06-27 09:36:52 -040060 tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&); // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000061 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050062 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000063 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050064 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); // constexpr in C++20
Hui Xied1637a82022-05-12 13:23:11 +010065 template<class Alloc, class... UTypes>
66 constexpr explicit(see-below)
67 tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&&); // C++23
68 template<class Alloc, class U1, class U2>
69 constexpr explicit(see-below)
70 tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&); // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000071 template <class Alloc, class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050072 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 +000073 template <class Alloc, class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050074 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); // constexpr in C++20
Hui Xied1637a82022-05-12 13:23:11 +010075 template<class Alloc, class U1, class U2>
76 constexpr explicit(see-below)
77 tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&&); // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000078
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050079 tuple& operator=(const tuple&); // constexpr in C++20
Hui Xied1637a82022-05-12 13:23:11 +010080 constexpr const tuple& operator=(const tuple&) const; // C++23
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050081 tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...); // constexpr in C++20
Hui Xied1637a82022-05-12 13:23:11 +010082 constexpr const tuple& operator=(tuple&&) const; // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000083 template <class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050084 tuple& operator=(const tuple<U...>&); // constexpr in C++20
Hui Xied1637a82022-05-12 13:23:11 +010085 template<class... UTypes>
86 constexpr const tuple& operator=(const tuple<UTypes...>&) const; // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000087 template <class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050088 tuple& operator=(tuple<U...>&&); // constexpr in C++20
Hui Xied1637a82022-05-12 13:23:11 +010089 template<class... UTypes>
90 constexpr const tuple& operator=(tuple<UTypes...>&&) const; // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000091 template <class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050092 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++20
Hui Xied1637a82022-05-12 13:23:11 +010093 template<class U1, class U2>
94 constexpr const tuple& operator=(const pair<U1, U2>&) const; // iff sizeof...(Types) == 2 // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000095 template <class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050096 tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++20
Hui Xied1637a82022-05-12 13:23:11 +010097 template<class U1, class U2>
98 constexpr const tuple& operator=(pair<U1, U2>&&) const; // iff sizeof...(Types) == 2 // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +000099
Louis Dionne6c0d5342018-07-31 11:56:20 -0400100 template<class U, size_t N>
101 tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
102 template<class U, size_t N>
103 tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
104
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500105 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); // constexpr in C++20
Hui Xied1637a82022-05-12 13:23:11 +0100106 constexpr void swap(const tuple&) const noexcept(see-below); // C++23
Howard Hinnantc51e1022010-05-11 19:42:16 +0000107};
108
Nikolas Klauserad26ba52022-01-17 19:45:42 +0100109
110template<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23
111 requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; }
112struct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> {
113 using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
114};
115
116template<class... TTypes, class... UTypes> // since C++23
117 requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; }
118struct common_type<tuple<TTypes...>, tuple<UTypes...>> {
119 using type = tuple<common_type_t<TTypes, UTypes>...>;
120};
121
Louis Dionne616da2a2019-08-12 18:30:31 +0000122template <class ...T>
123tuple(T...) -> tuple<T...>; // since C++17
124template <class T1, class T2>
125tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
126template <class Alloc, class ...T>
127tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
128template <class Alloc, class T1, class T2>
129tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
130template <class Alloc, class ...T>
131tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
132
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000133inline constexpr unspecified ignore;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000134
Marshall Clow2229cee2013-07-22 16:02:19 +0000135template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clowded420b2013-10-05 18:46:37 +0000136template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clowa8892812014-02-25 16:11:46 +0000137template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clow2229cee2013-07-22 16:02:19 +0000138template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier8e892c52016-07-18 00:35:56 +0000139
140// [tuple.apply], calling a function with a tuple of arguments:
141template <class F, class Tuple>
142 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
143template <class T, class Tuple>
144 constexpr T make_from_tuple(Tuple&& t); // C++17
145
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146// 20.4.1.4, tuple helper classes:
Marshall Clowce62b4d2019-01-11 21:57:12 +0000147template <class T> struct tuple_size; // undefined
148template <class... T> struct tuple_size<tuple<T...>>;
Eric Fiselier8e892c52016-07-18 00:35:56 +0000149template <class T>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000150 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Louis Dionnee684aa62019-04-01 16:39:34 +0000151template <size_t I, class T> struct tuple_element; // undefined
152template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
Marshall Clow36907512015-11-19 19:45:29 +0000153template <size_t I, class T>
154 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155
156// 20.4.1.5, element access:
Marshall Clow36907512015-11-19 19:45:29 +0000157template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000158 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000159 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000160template <size_t I, class... T>
161 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000162 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000163template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000164 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow0abb1042013-07-17 18:25:36 +0000165 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000166template <size_t I, class... T>
167 const typename tuple_element<I, tuple<T...>>::type&&
168 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169
Marshall Clow15b02e02013-07-13 02:54:05 +0000170template <class T1, class... T>
171 constexpr T1& get(tuple<T...>&) noexcept; // C++14
172template <class T1, class... T>
Marshall Clow36907512015-11-19 19:45:29 +0000173 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000174template <class T1, class... T>
175 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000176template <class T1, class... T>
177 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000178
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179// 20.4.1.6, relational operators:
Marshall Clow2229cee2013-07-22 16:02:19 +0000180template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Kent Ross0861b0d2021-10-08 14:54:28 -0700181template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
182template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
183template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
184template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
185template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20
186template<class... T, class... U>
187 constexpr common_comparison_category_t<synth-three-way-result<T, U>...>
188 operator<=>(const tuple<T...>&, const tuple<U...>&); // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189
190template <class... Types, class Alloc>
191 struct uses_allocator<tuple<Types...>, Alloc>;
192
193template <class... Types>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000194 void
195 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196
Hui Xied1637a82022-05-12 13:23:11 +0100197template <class... Types>
198 constexpr void swap(const tuple<Types...>& x, const tuple<Types...>& y) noexcept(see-below); // C++23
199
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200} // std
201
202*/
203
Louis Dionneb4fce352022-03-25 12:55:36 -0400204#include <__assert> // all public C++ headers provide the assertion handler
Kent Ross0861b0d2021-10-08 14:54:28 -0700205#include <__compare/common_comparison_category.h>
206#include <__compare/synth_three_way.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207#include <__config>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000208#include <__functional/unwrap_ref.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400209#include <__memory/allocator_arg_t.h>
210#include <__memory/uses_allocator.h>
211#include <__tuple>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000212#include <__utility/forward.h>
Kent Ross0861b0d2021-10-08 14:54:28 -0700213#include <__utility/integer_sequence.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000214#include <__utility/move.h>
Nikolas Klauser8fccd622022-03-05 19:17:07 +0100215#include <__utility/pair.h>
216#include <__utility/piecewise_construct.h>
217#include <__utility/swap.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000220#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221
Louis Dionne22355cc2022-06-27 15:53:41 -0400222#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
223# include <exception>
224# include <iosfwd>
225# include <new>
226# include <typeinfo>
227# include <utility>
228#endif
229
Nikolas Klausera0e0edb2022-06-16 22:43:46 +0200230// standard-mandated includes
231#include <compare>
232
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000233#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500234# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000235#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000236
237_LIBCPP_BEGIN_NAMESPACE_STD
238
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000239#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240
Marshall Clowf50d66f2014-03-03 06:18:11 +0000241
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242// __tuple_leaf
243
Eric Fiselierf7394302015-06-13 07:08:02 +0000244template <size_t _Ip, class _Hp,
245 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000246 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247class __tuple_leaf;
248
249template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500250inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000252 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253{
254 swap(__x.get(), __y.get());
255}
256
Hui Xied1637a82022-05-12 13:23:11 +0100257template <size_t _Ip, class _Hp, bool _Ep>
258_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne76450ee2022-06-27 09:36:52 -0400259void swap(const __tuple_leaf<_Ip, _Hp, _Ep>& __x, const __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Hui Xied1637a82022-05-12 13:23:11 +0100260 _NOEXCEPT_(__is_nothrow_swappable<const _Hp>::value) {
261 swap(__x.get(), __y.get());
262}
263
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264template <size_t _Ip, class _Hp, bool>
265class __tuple_leaf
266{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000267 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268
Eric Fiselierca8bba12016-07-20 02:57:39 +0000269 template <class _Tp>
270 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000271#if __has_keyword(__reference_binds_to_temporary)
272 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000273#else
274 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000275#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000276 }
277
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500278 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279 __tuple_leaf& operator=(const __tuple_leaf&);
280public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500281 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000282 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000283 {static_assert(!is_reference<_Hp>::value,
284 "Attempted to default construct a reference element in a tuple");}
285
286 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500287 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000289 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290 {static_assert(!is_reference<_Hp>::value,
291 "Attempted to default construct a reference element in a tuple");}
292
293 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500294 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000296 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000297 {static_assert(!is_reference<_Hp>::value,
298 "Attempted to default construct a reference element in a tuple");}
299
300 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500301 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000303 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304 {static_assert(!is_reference<_Hp>::value,
305 "Attempted to default construct a reference element in a tuple");}
306
Howard Hinnant693fc212010-09-27 17:54:17 +0000307 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400308 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000309 _And<
310 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
311 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000312 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000313 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000314 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000315 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000316 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000317 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000318 {static_assert(__can_bind_reference<_Tp&&>(),
319 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320
321 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500322 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000323 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000324 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000325 {static_assert(__can_bind_reference<_Tp&&>(),
326 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327
328 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500329 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000331 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000332 {static_assert(!is_reference<_Hp>::value,
333 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000334
335 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500336 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000337 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000338 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000339 {static_assert(!is_reference<_Hp>::value,
340 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341
Marshall Clow47fcee52014-04-21 23:48:09 +0000342 __tuple_leaf(const __tuple_leaf& __t) = default;
343 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500345 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000346 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000348 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349 return 0;
350 }
351
Hui Xied1637a82022-05-12 13:23:11 +0100352 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
353 int swap(const __tuple_leaf& __t) const _NOEXCEPT_(__is_nothrow_swappable<const __tuple_leaf>::value) {
354 _VSTD::swap(*this, __t);
355 return 0;
356 }
357
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000358 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
359 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360};
361
362template <size_t _Ip, class _Hp>
363class __tuple_leaf<_Ip, _Hp, true>
364 : private _Hp
365{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500366 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367 __tuple_leaf& operator=(const __tuple_leaf&);
368public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500369 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000370 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000371
372 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500373 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
375
376 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500377 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
379 : _Hp(allocator_arg_t(), __a) {}
380
381 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500382 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
384 : _Hp(__a) {}
385
Howard Hinnant693fc212010-09-27 17:54:17 +0000386 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400387 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000388 _And<
389 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
390 is_constructible<_Hp, _Tp>
391 >::value
392 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000393 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000394 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000395 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000396 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397
398 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500399 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000401 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402
403 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500404 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000406 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407
408 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500409 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000411 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000413 __tuple_leaf(__tuple_leaf const &) = default;
414 __tuple_leaf(__tuple_leaf &&) = default;
415
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500416 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000417 int
418 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000420 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421 return 0;
422 }
423
Hui Xied1637a82022-05-12 13:23:11 +0100424 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
425 int swap(const __tuple_leaf& __rhs) const _NOEXCEPT_(__is_nothrow_swappable<const __tuple_leaf>::value) {
426 _VSTD::swap(*this, __rhs);
427 return 0;
428 }
429
Marshall Clow2229cee2013-07-22 16:02:19 +0000430 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
431 _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 +0000432};
433
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000434template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500435_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000436void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000437
Marshall Clowc470eae2014-10-15 10:33:02 +0000438template <class _Tp>
439struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000440
Marshall Clowc470eae2014-10-15 10:33:02 +0000441template <class ..._Tp>
442struct __all_default_constructible<__tuple_types<_Tp...>>
443 : __all<is_default_constructible<_Tp>::value...>
444{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000445
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446// __tuple_impl
447
448template<class _Indx, class ..._Tp> struct __tuple_impl;
449
450template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000451struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452 : public __tuple_leaf<_Indx, _Tp>...
453{
Howard Hinnant38469632012-07-06 20:39:45 +0000454 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500455 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000456 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000457
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458 template <size_t ..._Uf, class ..._Tf,
459 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000460 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461 explicit
462 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
463 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000464 _Up&&... __u)
465 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
466 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000467 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 __tuple_leaf<_Ul, _Tl>()...
469 {}
470
471 template <class _Alloc, size_t ..._Uf, class ..._Tf,
472 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500473 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474 explicit
475 __tuple_impl(allocator_arg_t, const _Alloc& __a,
476 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
477 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
478 _Up&&... __u) :
479 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000480 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000481 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
482 {}
483
484 template <class _Tuple,
485 class = typename enable_if
486 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000487 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488 >::type
489 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000490 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000491 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
492 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000493 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
494 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495 {}
496
497 template <class _Alloc, class _Tuple,
498 class = typename enable_if
499 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000500 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 >::type
502 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500503 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
505 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000506 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000507 _VSTD::forward<typename tuple_element<_Indx,
508 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509 {}
510
Howard Hinnant0d032d12013-11-06 17:45:43 +0000511 __tuple_impl(const __tuple_impl&) = default;
512 __tuple_impl(__tuple_impl&&) = default;
513
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500514 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000516 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400518 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519 }
Hui Xied1637a82022-05-12 13:23:11 +0100520
521 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
522 void swap(const __tuple_impl& __t) const
523 _NOEXCEPT_(__all<__is_nothrow_swappable<const _Tp>::value...>::value)
524 {
525 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...);
526 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527};
528
Louis Dionne6c0d5342018-07-31 11:56:20 -0400529template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500530_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400531void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
532 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
533}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000534
Louis Dionne6c0d5342018-07-31 11:56:20 -0400535template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500536_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400537void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
538 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500539 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400540 ), void(), 0)...);
541}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000542
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000544class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000545{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000546 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000548 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549
Marshall Clow0abb1042013-07-17 18:25:36 +0000550 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000551 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000552 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000553 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000554 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000555 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000556 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
557 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500559 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560
Louis Dionne574e2e32021-02-10 16:19:50 -0500561 // tuple() constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400562 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500563 _And<
564 _IsImpDefault<_Tp>... // explicit check
565 >::value
566 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400567 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000568 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500569 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
570 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000571
Louis Dionne574e2e32021-02-10 16:19:50 -0500572 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400573 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500574 _And<
575 _IsDefault<_Tp>...,
576 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
577 >::value
578 , int> = 0>
579 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
580 explicit tuple()
581 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
582 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000583
Louis Dionne9ce598d2021-09-08 09:14:43 -0400584 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500585 _And<
586 _IsImpDefault<_Tp>... // explicit check
587 >::value
588 , int> = 0>
589 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
590 tuple(allocator_arg_t, _Alloc const& __a)
591 : __base_(allocator_arg_t(), __a,
592 __tuple_indices<>(), __tuple_types<>(),
593 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
594 __tuple_types<_Tp...>()) {}
595
596 template <class _Alloc,
597 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400598 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500599 _And<
600 _IsDefault<_Tp>...,
601 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
602 >::value
603 , int> = 0>
604 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
605 explicit tuple(allocator_arg_t, _Alloc const& __a)
606 : __base_(allocator_arg_t(), __a,
607 __tuple_indices<>(), __tuple_types<>(),
608 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
609 __tuple_types<_Tp...>()) {}
610
611 // tuple(const T&...) constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400612 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500613 _And<
614 _BoolConstant<sizeof...(_Tp) >= 1>,
615 is_copy_constructible<_Tp>...,
616 is_convertible<const _Tp&, _Tp>... // explicit check
617 >::value
618 , int> = 0>
619 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
620 tuple(const _Tp& ... __t)
621 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
622 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
623 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
624 typename __make_tuple_indices<0>::type(),
625 typename __make_tuple_types<tuple, 0>::type(),
626 __t...
627 ) {}
628
Louis Dionne9ce598d2021-09-08 09:14:43 -0400629 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500630 _And<
631 _BoolConstant<sizeof...(_Tp) >= 1>,
632 is_copy_constructible<_Tp>...,
633 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
634 >::value
635 , int> = 0>
636 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
637 explicit tuple(const _Tp& ... __t)
638 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
639 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
640 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
641 typename __make_tuple_indices<0>::type(),
642 typename __make_tuple_types<tuple, 0>::type(),
643 __t...
644 ) {}
645
Louis Dionne9ce598d2021-09-08 09:14:43 -0400646 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500647 _And<
648 _BoolConstant<sizeof...(_Tp) >= 1>,
649 is_copy_constructible<_Tp>...,
650 is_convertible<const _Tp&, _Tp>... // explicit check
651 >::value
652 , int> = 0>
653 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
654 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
655 : __base_(allocator_arg_t(), __a,
656 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
657 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
658 typename __make_tuple_indices<0>::type(),
659 typename __make_tuple_types<tuple, 0>::type(),
660 __t...
661 ) {}
662
Louis Dionne9ce598d2021-09-08 09:14:43 -0400663 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500664 _And<
665 _BoolConstant<sizeof...(_Tp) >= 1>,
666 is_copy_constructible<_Tp>...,
667 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
668 >::value
669 , int> = 0>
670 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
671 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
672 : __base_(allocator_arg_t(), __a,
673 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
674 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
675 typename __make_tuple_indices<0>::type(),
676 typename __make_tuple_types<tuple, 0>::type(),
677 __t...
678 ) {}
679
680 // tuple(U&& ...) constructors (including allocator_arg_t variants)
681 template <class ..._Up> struct _IsThisTuple : false_type { };
682 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
683
684 template <class ..._Up>
685 struct _EnableUTypesCtor : _And<
686 _BoolConstant<sizeof...(_Tp) >= 1>,
687 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
688 is_constructible<_Tp, _Up>...
689 > { };
690
Louis Dionne9ce598d2021-09-08 09:14:43 -0400691 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500692 _And<
693 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
694 _EnableUTypesCtor<_Up...>,
695 is_convertible<_Up, _Tp>... // explicit check
696 >::value
697 , int> = 0>
698 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
699 tuple(_Up&&... __u)
700 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
701 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
702 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
703 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
704 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
705 _VSTD::forward<_Up>(__u)...) {}
706
Louis Dionne9ce598d2021-09-08 09:14:43 -0400707 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500708 _And<
709 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
710 _EnableUTypesCtor<_Up...>,
711 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
712 >::value
713 , int> = 0>
714 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
715 explicit tuple(_Up&&... __u)
716 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
717 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
718 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
719 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
720 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
721 _VSTD::forward<_Up>(__u)...) {}
722
Louis Dionne9ce598d2021-09-08 09:14:43 -0400723 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500724 _And<
725 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
726 _EnableUTypesCtor<_Up...>,
727 is_convertible<_Up, _Tp>... // explicit check
728 >::value
729 , int> = 0>
730 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
731 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
732 : __base_(allocator_arg_t(), __a,
733 typename __make_tuple_indices<sizeof...(_Up)>::type(),
734 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
735 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
736 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
737 _VSTD::forward<_Up>(__u)...) {}
738
Louis Dionne9ce598d2021-09-08 09:14:43 -0400739 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500740 _And<
741 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
742 _EnableUTypesCtor<_Up...>,
743 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
744 >::value
745 , int> = 0>
746 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
747 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
748 : __base_(allocator_arg_t(), __a,
749 typename __make_tuple_indices<sizeof...(_Up)>::type(),
750 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
751 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
752 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
753 _VSTD::forward<_Up>(__u)...) {}
754
755 // Copy and move constructors (including the allocator_arg_t variants)
756 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000757 tuple(tuple&&) = default;
758
Louis Dionne9ce598d2021-09-08 09:14:43 -0400759 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500760 _And<is_copy_constructible<_Tp>...>::value
761 , int> = 0>
Hui Xied1637a82022-05-12 13:23:11 +0100762 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500763 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
764 : __base_(allocator_arg_t(), __alloc, __t)
765 { }
766
Louis Dionne9ce598d2021-09-08 09:14:43 -0400767 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500768 _And<is_move_constructible<_Tp>...>::value
769 , int> = 0>
Hui Xied1637a82022-05-12 13:23:11 +0100770 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500771 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
772 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
773 { }
774
775 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
Louis Dionne76450ee2022-06-27 09:36:52 -0400776
Hui Xied1637a82022-05-12 13:23:11 +0100777 template <class _OtherTuple, class _DecayedOtherTuple = __uncvref_t<_OtherTuple>, class = void>
778 struct _EnableCtorFromUTypesTuple : false_type {};
779
780 template <class _OtherTuple, class... _Up>
Louis Dionne76450ee2022-06-27 09:36:52 -0400781 struct _EnableCtorFromUTypesTuple<_OtherTuple, tuple<_Up...>,
Hui Xied1637a82022-05-12 13:23:11 +0100782 // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below
783 __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>> : _And<
784 // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor can work.
785 // Otherwise, is_constructible can trigger hard error in those cases https://godbolt.org/z/M94cGdKcE
786 _Not<is_same<_OtherTuple, const tuple&> >,
787 _Not<is_same<_OtherTuple, tuple&&> >,
788 is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,
789 _Lazy<_Or, _BoolConstant<sizeof...(_Tp) != 1>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500790 // _Tp and _Up are 1-element packs - the pack expansions look
791 // weird to avoid tripping up the type traits in degenerate cases
792 _Lazy<_And,
Hui Xied1637a82022-05-12 13:23:11 +0100793 _Not<is_same<_Tp, _Up> >...,
794 _Not<is_convertible<_OtherTuple, _Tp> >...,
795 _Not<is_constructible<_Tp, _OtherTuple> >...
Louis Dionne574e2e32021-02-10 16:19:50 -0500796 >
Hui Xied1637a82022-05-12 13:23:11 +0100797 >
798 > {};
Louis Dionne574e2e32021-02-10 16:19:50 -0500799
Louis Dionne9ce598d2021-09-08 09:14:43 -0400800 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500801 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100802 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500803 is_convertible<const _Up&, _Tp>... // explicit check
804 >::value
805 , int> = 0>
806 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
807 tuple(const tuple<_Up...>& __t)
808 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
809 : __base_(__t)
810 { }
811
Louis Dionne9ce598d2021-09-08 09:14:43 -0400812 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500813 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100814 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500815 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
816 >::value
817 , int> = 0>
818 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
819 explicit tuple(const tuple<_Up...>& __t)
820 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
821 : __base_(__t)
822 { }
823
Louis Dionne9ce598d2021-09-08 09:14:43 -0400824 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500825 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100826 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500827 is_convertible<const _Up&, _Tp>... // explicit check
828 >::value
829 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500830 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500831 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
832 : __base_(allocator_arg_t(), __a, __t)
833 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000834
Louis Dionne9ce598d2021-09-08 09:14:43 -0400835 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500836 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100837 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500838 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
839 >::value
840 , int> = 0>
841 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
842 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
843 : __base_(allocator_arg_t(), __a, __t)
844 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000845
Hui Xied1637a82022-05-12 13:23:11 +0100846#if _LIBCPP_STD_VER > 20
847 // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
848
849 template <class... _Up, enable_if_t<
850 _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
851 _LIBCPP_HIDE_FROM_ABI constexpr
852 explicit(!(is_convertible_v<_Up&, _Tp> && ...))
853 tuple(tuple<_Up...>& __t) : __base_(__t) {}
854
855 template <class _Alloc, class... _Up, enable_if_t<
856 _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
857 _LIBCPP_HIDE_FROM_ABI constexpr
858 explicit(!(is_convertible_v<_Up&, _Tp> && ...))
859 tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t) : __base_(allocator_arg_t(), __alloc, __t) {}
860#endif // _LIBCPP_STD_VER > 20
861
Louis Dionne574e2e32021-02-10 16:19:50 -0500862 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
Louis Dionne574e2e32021-02-10 16:19:50 -0500863
Louis Dionne9ce598d2021-09-08 09:14:43 -0400864 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500865 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100866 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500867 is_convertible<_Up, _Tp>... // explicit check
868 >::value
869 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000870 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500871 tuple(tuple<_Up...>&& __t)
872 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
873 : __base_(_VSTD::move(__t))
874 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875
Louis Dionne9ce598d2021-09-08 09:14:43 -0400876 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500877 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100878 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500879 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
880 >::value
881 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000882 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500883 explicit tuple(tuple<_Up...>&& __t)
884 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
885 : __base_(_VSTD::move(__t))
886 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000887
Louis Dionne9ce598d2021-09-08 09:14:43 -0400888 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500889 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100890 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500891 is_convertible<_Up, _Tp>... // explicit check
892 >::value
893 , int> = 0>
894 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
895 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
896 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
897 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898
Louis Dionne9ce598d2021-09-08 09:14:43 -0400899 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500900 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100901 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500902 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
903 >::value
904 , int> = 0>
905 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
906 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
907 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
908 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000909
Hui Xied1637a82022-05-12 13:23:11 +0100910#if _LIBCPP_STD_VER > 20
911 // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
Hui Xiea3ac9222022-05-12 13:23:11 +0100912
Hui Xied1637a82022-05-12 13:23:11 +0100913 template <class... _Up, enable_if_t<
914 _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
915 _LIBCPP_HIDE_FROM_ABI constexpr
916 explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
917 tuple(const tuple<_Up...>&& __t) : __base_(std::move(__t)) {}
918
919 template <class _Alloc, class... _Up, enable_if_t<
920 _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
921 _LIBCPP_HIDE_FROM_ABI constexpr
922 explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
923 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
924 : __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
925#endif // _LIBCPP_STD_VER > 20
926
927 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
928
929 template <template <class...> class Pred, class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
930 struct _CtorPredicateFromPair : false_type{};
931
932 template <template <class...> class Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
933 struct _CtorPredicateFromPair<Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
934 Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >,
935 Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> >
936 > {};
937
938 template <class _Pair>
939 struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair>{};
940
941 template <class _Pair>
942 struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair>{};
943
944 template <class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
945 struct _BothImplicitlyConvertible : false_type{};
946
947 template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
948 struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
949 is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>,
950 is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2>
951 > {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952
Louis Dionne9ce598d2021-09-08 09:14:43 -0400953 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500954 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100955 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
956 _BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500957 >::value
958 , int> = 0>
959 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
960 tuple(const pair<_Up1, _Up2>& __p)
Hui Xied1637a82022-05-12 13:23:11 +0100961 _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -0500962 : __base_(__p)
963 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964
Louis Dionne9ce598d2021-09-08 09:14:43 -0400965 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500966 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100967 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
968 _Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500969 >::value
970 , int> = 0>
971 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
972 explicit tuple(const pair<_Up1, _Up2>& __p)
Hui Xied1637a82022-05-12 13:23:11 +0100973 _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -0500974 : __base_(__p)
975 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000976
Louis Dionne9ce598d2021-09-08 09:14:43 -0400977 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500978 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100979 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
980 _BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500981 >::value
982 , int> = 0>
983 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
984 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
985 : __base_(allocator_arg_t(), __a, __p)
986 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987
Louis Dionne9ce598d2021-09-08 09:14:43 -0400988 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500989 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100990 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
991 _Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500992 >::value
993 , int> = 0>
994 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
995 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
996 : __base_(allocator_arg_t(), __a, __p)
997 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000998
Hui Xied1637a82022-05-12 13:23:11 +0100999#if _LIBCPP_STD_VER > 20
1000 // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
Hui Xie39360e22022-06-23 21:54:23 +01001001
Hui Xied1637a82022-05-12 13:23:11 +01001002 template <class _U1, class _U2, enable_if_t<
1003 _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
1004 _LIBCPP_HIDE_FROM_ABI constexpr
1005 explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
1006 tuple(pair<_U1, _U2>& __p) : __base_(__p) {}
1007
1008 template <class _Alloc, class _U1, class _U2, enable_if_t<
1009 _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>
1010 _LIBCPP_HIDE_FROM_ABI constexpr
1011 explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
1012 tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p) : __base_(allocator_arg_t(), __alloc, __p) {}
1013#endif
1014
1015 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016
Louis Dionne9ce598d2021-09-08 09:14:43 -04001017 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001018 _And<
Hui Xied1637a82022-05-12 13:23:11 +01001019 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1020 _BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001021 >::value
1022 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -04001023 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -05001024 tuple(pair<_Up1, _Up2>&& __p)
Hui Xied1637a82022-05-12 13:23:11 +01001025 _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -05001026 : __base_(_VSTD::move(__p))
1027 { }
1028
Louis Dionne9ce598d2021-09-08 09:14:43 -04001029 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001030 _And<
Hui Xied1637a82022-05-12 13:23:11 +01001031 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1032 _Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001033 >::value
1034 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -04001035 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -05001036 explicit tuple(pair<_Up1, _Up2>&& __p)
Hui Xied1637a82022-05-12 13:23:11 +01001037 _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -05001038 : __base_(_VSTD::move(__p))
1039 { }
1040
Louis Dionne9ce598d2021-09-08 09:14:43 -04001041 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001042 _And<
Hui Xied1637a82022-05-12 13:23:11 +01001043 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1044 _BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001045 >::value
1046 , int> = 0>
1047 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1048 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
1049 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
1050 { }
1051
Louis Dionne9ce598d2021-09-08 09:14:43 -04001052 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001053 _And<
Hui Xied1637a82022-05-12 13:23:11 +01001054 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1055 _Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001056 >::value
1057 , int> = 0>
1058 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1059 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
1060 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
1061 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +00001062
Hui Xied1637a82022-05-12 13:23:11 +01001063#if _LIBCPP_STD_VER > 20
1064 // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
1065
1066 template <class _U1, class _U2, enable_if_t<
1067 _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
1068 _LIBCPP_HIDE_FROM_ABI constexpr
1069 explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
1070 tuple(const pair<_U1, _U2>&& __p) : __base_(std::move(__p)) {}
1071
1072 template <class _Alloc, class _U1, class _U2, enable_if_t<
1073 _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
1074 _LIBCPP_HIDE_FROM_ABI constexpr
1075 explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
1076 tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
1077 : __base_(allocator_arg_t(), __alloc, std::move(__p)) {}
1078#endif // _LIBCPP_STD_VER > 20
1079
Louis Dionne6c0d5342018-07-31 11:56:20 -04001080 // [tuple.assign]
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=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
1083 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +00001084 {
Louis Dionne6c0d5342018-07-31 11:56:20 -04001085 _VSTD::__memberwise_copy_assign(*this, __tuple,
1086 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +00001087 return *this;
1088 }
1089
Hui Xied1637a82022-05-12 13:23:11 +01001090#if _LIBCPP_STD_VER > 20
1091 _LIBCPP_HIDE_FROM_ABI constexpr
1092 const tuple& operator=(tuple const& __tuple) const
1093 requires (_And<is_copy_assignable<const _Tp>...>::value) {
1094 std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
1095 return *this;
1096 }
1097
1098 _LIBCPP_HIDE_FROM_ABI constexpr
1099 const tuple& operator=(tuple&& __tuple) const
1100 requires (_And<is_assignable<const _Tp&, _Tp>...>::value) {
1101 std::__memberwise_forward_assign(*this,
1102 std::move(__tuple),
1103 __tuple_types<_Tp...>(),
1104 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1105 return *this;
1106 }
1107#endif // _LIBCPP_STD_VER > 20
1108
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001109 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001110 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
1111 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +00001112 {
Louis Dionne6c0d5342018-07-31 11:56:20 -04001113 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1114 __tuple_types<_Tp...>(),
1115 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +00001116 return *this;
1117 }
1118
Louis Dionne9ce598d2021-09-08 09:14:43 -04001119 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001120 _And<
1121 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1122 is_assignable<_Tp&, _Up const&>...
1123 >::value
1124 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001125 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001126 tuple& operator=(tuple<_Up...> const& __tuple)
1127 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1128 {
1129 _VSTD::__memberwise_copy_assign(*this, __tuple,
1130 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1131 return *this;
1132 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001133
Louis Dionne9ce598d2021-09-08 09:14:43 -04001134 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001135 _And<
1136 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1137 is_assignable<_Tp&, _Up>...
1138 >::value
1139 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001140 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001141 tuple& operator=(tuple<_Up...>&& __tuple)
1142 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1143 {
1144 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1145 __tuple_types<_Up...>(),
1146 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1147 return *this;
1148 }
1149
Hui Xied1637a82022-05-12 13:23:11 +01001150
1151#if _LIBCPP_STD_VER > 20
1152 template <class... _UTypes, enable_if_t<
1153 _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
1154 is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
1155 _LIBCPP_HIDE_FROM_ABI constexpr
1156 const tuple& operator=(const tuple<_UTypes...>& __u) const {
1157 std::__memberwise_copy_assign(*this,
1158 __u,
1159 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1160 return *this;
1161 }
1162
1163 template <class... _UTypes, enable_if_t<
1164 _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
1165 is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
1166 _LIBCPP_HIDE_FROM_ABI constexpr
1167 const tuple& operator=(tuple<_UTypes...>&& __u) const {
1168 std::__memberwise_forward_assign(*this,
1169 __u,
1170 __tuple_types<_UTypes...>(),
1171 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1172 return *this;
1173 }
1174#endif // _LIBCPP_STD_VER > 20
1175
Louis Dionne76450ee2022-06-27 09:36:52 -04001176 template <template<class...> class Pred, bool _Const,
Hui Xied1637a82022-05-12 13:23:11 +01001177 class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
1178 struct _AssignPredicateFromPair : false_type {};
1179
Louis Dionne76450ee2022-06-27 09:36:52 -04001180 template <template<class...> class Pred, bool _Const,
Hui Xied1637a82022-05-12 13:23:11 +01001181 class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
Louis Dionne76450ee2022-06-27 09:36:52 -04001182 struct _AssignPredicateFromPair<Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > :
Hui Xied1637a82022-05-12 13:23:11 +01001183 _And<Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,
1184 Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> >
1185 > {};
1186
1187 template <bool _Const, class _Pair>
1188 struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};
1189
1190 template <bool _Const, class _Pair>
1191 struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
1192
1193#if _LIBCPP_STD_VER > 20
1194 template <class _U1, class _U2, enable_if_t<
1195 _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
1196 _LIBCPP_HIDE_FROM_ABI constexpr
1197 const tuple& operator=(const pair<_U1, _U2>& __pair) const
1198 noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
1199 std::get<0>(*this) = __pair.first;
1200 std::get<1>(*this) = __pair.second;
1201 return *this;
1202 }
1203
1204 template <class _U1, class _U2, enable_if_t<
1205 _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>
1206 _LIBCPP_HIDE_FROM_ABI constexpr
1207 const tuple& operator=(pair<_U1, _U2>&& __pair) const
1208 noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {
1209 std::get<0>(*this) = std::move(__pair.first);
1210 std::get<1>(*this) = std::move(__pair.second);
1211 return *this;
1212 }
1213#endif // _LIBCPP_STD_VER > 20
1214
1215 template<class _Up1, class _Up2, __enable_if_t<
1216 _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value
Louis Dionne6c0d5342018-07-31 11:56:20 -04001217 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001218 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001219 tuple& operator=(pair<_Up1, _Up2> const& __pair)
Hui Xied1637a82022-05-12 13:23:11 +01001220 _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value))
Louis Dionne6c0d5342018-07-31 11:56:20 -04001221 {
1222 _VSTD::get<0>(*this) = __pair.first;
1223 _VSTD::get<1>(*this) = __pair.second;
1224 return *this;
1225 }
1226
Hui Xied1637a82022-05-12 13:23:11 +01001227 template<class _Up1, class _Up2, __enable_if_t<
1228 _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value
Louis Dionne6c0d5342018-07-31 11:56:20 -04001229 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001230 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001231 tuple& operator=(pair<_Up1, _Up2>&& __pair)
Hui Xied1637a82022-05-12 13:23:11 +01001232 _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value))
Louis Dionne6c0d5342018-07-31 11:56:20 -04001233 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001234 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1235 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001236 return *this;
1237 }
1238
1239 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001240 template<class _Up, size_t _Np, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001241 _And<
1242 _BoolConstant<_Np == sizeof...(_Tp)>,
1243 is_assignable<_Tp&, _Up const&>...
1244 >::value
1245 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001246 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001247 tuple& operator=(array<_Up, _Np> const& __array)
1248 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1249 {
1250 _VSTD::__memberwise_copy_assign(*this, __array,
1251 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1252 return *this;
1253 }
1254
1255 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001256 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001257 _And<
1258 _BoolConstant<_Np == sizeof...(_Tp)>,
1259 is_assignable<_Tp&, _Up>...
1260 >::value
1261 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001262 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001263 tuple& operator=(array<_Up, _Np>&& __array)
1264 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1265 {
1266 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1267 __tuple_types<_If<true, _Up, _Tp>...>(),
1268 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1269 return *this;
1270 }
1271
1272 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001273 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001274 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001275 {__base_.swap(__t.__base_);}
Hui Xied1637a82022-05-12 13:23:11 +01001276
1277#if _LIBCPP_STD_VER > 20
1278 _LIBCPP_HIDE_FROM_ABI constexpr
1279 void swap(const tuple& __t) const noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
1280 __base_.swap(__t.__base_);
1281 }
1282#endif // _LIBCPP_STD_VER > 20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283};
1284
1285template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001286class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287{
1288public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001289 _LIBCPP_INLINE_VISIBILITY constexpr
1290 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001291 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001292 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001293 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001295 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001296 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001297 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001298 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001299 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001300 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001301 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001302 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001303 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001304 void swap(tuple&) _NOEXCEPT {}
Hui Xied1637a82022-05-12 13:23:11 +01001305#if _LIBCPP_STD_VER > 20
1306 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
1307#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308};
1309
Joe Loserd9b3d972022-03-12 10:46:57 -05001310#if _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001311template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1312 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1313struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1314 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1315};
1316
1317template <class... _TTypes, class... _UTypes>
1318 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1319struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1320 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1321};
Joe Loserd9b3d972022-03-12 10:46:57 -05001322#endif // _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001323
1324#if _LIBCPP_STD_VER > 14
Louis Dionne616da2a2019-08-12 18:30:31 +00001325template <class ..._Tp>
1326tuple(_Tp...) -> tuple<_Tp...>;
1327template <class _Tp1, class _Tp2>
1328tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1329template <class _Alloc, class ..._Tp>
1330tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1331template <class _Alloc, class _Tp1, class _Tp2>
1332tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1333template <class _Alloc, class ..._Tp>
1334tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001335#endif
1336
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001338inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001339typename enable_if
1340<
1341 __all<__is_swappable<_Tp>::value...>::value,
1342 void
1343>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001344swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1345 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1346 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001347
Hui Xied1637a82022-05-12 13:23:11 +01001348#if _LIBCPP_STD_VER > 20
1349template <class... _Tp>
1350_LIBCPP_HIDE_FROM_ABI constexpr
1351enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
1352swap(const tuple<_Tp...>& __lhs, const tuple<_Tp...>& __rhs)
1353 noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
1354 __lhs.swap(__rhs);
1355}
1356#endif
1357
Howard Hinnantc51e1022010-05-11 19:42:16 +00001358// get
1359
1360template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001361inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001362typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001363get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001365 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001366 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367}
1368
1369template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001370inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001371const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001372get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001374 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001375 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376}
1377
Howard Hinnant22e97242010-11-17 19:52:17 +00001378template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001379inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001380typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001381get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001382{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001383 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001384 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001385 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001386}
1387
Eric Fiselier6dea8092015-12-18 00:36:55 +00001388template <size_t _Ip, class ..._Tp>
1389inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1390const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1391get(const tuple<_Tp...>&& __t) _NOEXCEPT
1392{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001393 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001394 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001395 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001396}
1397
Marshall Clow15b02e02013-07-13 02:54:05 +00001398#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001399
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001400namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001401
Louis Dionne7dd28aa2021-07-20 11:46:05 -04001402static constexpr size_t __not_found = static_cast<size_t>(-1);
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001403static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001404
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001405inline _LIBCPP_INLINE_VISIBILITY
1406constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1407 return !__matches ? __res :
1408 (__res == __not_found ? __curr_i : __ambiguous);
1409}
Marshall Clow15b02e02013-07-13 02:54:05 +00001410
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001411template <size_t _Nx>
1412inline _LIBCPP_INLINE_VISIBILITY
1413constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1414 return __i == _Nx ? __not_found :
1415 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1416}
1417
1418template <class _T1, class ..._Args>
1419struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001420 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001421 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001422 static_assert(value != __not_found, "type not found in type list" );
1423 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001424};
1425
Eric Fiselier8087d302016-07-02 03:46:08 +00001426template <class _T1>
1427struct __find_exactly_one_checked<_T1> {
1428 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1429};
1430
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001431} // namespace __find_detail
Marshall Clow15b02e02013-07-13 02:54:05 +00001432
1433template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001434struct __find_exactly_one_t
1435 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1436};
Marshall Clow15b02e02013-07-13 02:54:05 +00001437
1438template <class _T1, class... _Args>
1439inline _LIBCPP_INLINE_VISIBILITY
1440constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1441{
1442 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1443}
1444
1445template <class _T1, class... _Args>
1446inline _LIBCPP_INLINE_VISIBILITY
1447constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1448{
1449 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1450}
1451
1452template <class _T1, class... _Args>
1453inline _LIBCPP_INLINE_VISIBILITY
1454constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1455{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001456 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001457}
1458
Eric Fiselier6dea8092015-12-18 00:36:55 +00001459template <class _T1, class... _Args>
1460inline _LIBCPP_INLINE_VISIBILITY
1461constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1462{
1463 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1464}
1465
Marshall Clow15b02e02013-07-13 02:54:05 +00001466#endif
1467
Howard Hinnantc51e1022010-05-11 19:42:16 +00001468// tie
1469
1470template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001471inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001473tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474{
1475 return tuple<_Tp&...>(__t...);
1476}
1477
1478template <class _Up>
1479struct __ignore_t
1480{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001481 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001482 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1483 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484};
1485
Eric Fiselier24e70262017-02-06 01:25:31 +00001486namespace {
Louis Dionne559be102021-09-22 09:35:32 -04001487 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001488} // namespace
Howard Hinnantc51e1022010-05-11 19:42:16 +00001489
Howard Hinnantc51e1022010-05-11 19:42:16 +00001490template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001491inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001492tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493make_tuple(_Tp&&... __t)
1494{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001495 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001496}
1497
Howard Hinnant3d203a32010-08-19 18:59:38 +00001498template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001499inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1500tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001501forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001502{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001503 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001504}
1505
Howard Hinnantc834c512011-11-29 18:15:50 +00001506template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507struct __tuple_equal
1508{
1509 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001510 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511 bool operator()(const _Tp& __x, const _Up& __y)
1512 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001513 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514 }
1515};
1516
1517template <>
1518struct __tuple_equal<0>
1519{
1520 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001521 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001522 bool operator()(const _Tp&, const _Up&)
1523 {
1524 return true;
1525 }
1526};
1527
1528template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001529inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001530bool
1531operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1532{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001533 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1535}
1536
Joe Loserd9b3d972022-03-12 10:46:57 -05001537#if _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001538
1539// operator<=>
1540
1541template <class ..._Tp, class ..._Up, size_t ..._Is>
1542_LIBCPP_HIDE_FROM_ABI constexpr
1543auto
1544__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1545 common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1546 static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1547 return __result;
1548}
1549
1550template <class ..._Tp, class ..._Up>
1551requires (sizeof...(_Tp) == sizeof...(_Up))
1552_LIBCPP_HIDE_FROM_ABI constexpr
1553common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1554operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1555{
1556 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1557}
1558
Joe Loserd9b3d972022-03-12 10:46:57 -05001559#else // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001560
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001562inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001563bool
1564operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1565{
1566 return !(__x == __y);
1567}
1568
Howard Hinnantc834c512011-11-29 18:15:50 +00001569template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001570struct __tuple_less
1571{
1572 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001573 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574 bool operator()(const _Tp& __x, const _Up& __y)
1575 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001576 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1577 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1578 return true;
1579 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1580 return false;
1581 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582 }
1583};
1584
1585template <>
1586struct __tuple_less<0>
1587{
1588 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001589 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590 bool operator()(const _Tp&, const _Up&)
1591 {
1592 return false;
1593 }
1594};
1595
1596template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001597inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598bool
1599operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1600{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001601 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1603}
1604
1605template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001606inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607bool
1608operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1609{
1610 return __y < __x;
1611}
1612
1613template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001614inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001615bool
1616operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1617{
1618 return !(__x < __y);
1619}
1620
1621template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001622inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001623bool
1624operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1625{
1626 return !(__y < __x);
1627}
1628
Joe Loserd9b3d972022-03-12 10:46:57 -05001629#endif // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001630
Howard Hinnantc51e1022010-05-11 19:42:16 +00001631// tuple_cat
1632
Howard Hinnant6256ee72010-12-11 20:47:50 +00001633template <class _Tp, class _Up> struct __tuple_cat_type;
1634
1635template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001636struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001638 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001639};
1640
1641template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1642struct __tuple_cat_return_1
1643{
1644};
1645
1646template <class ..._Types, class _Tuple0>
1647struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1648{
Nikolas Klauser669b4452022-02-17 22:53:20 +01001649 using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
1650 tuple<_Types...>,
1651 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
1652 >::type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001653};
1654
1655template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1656struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1657 : public __tuple_cat_return_1<
1658 typename __tuple_cat_type<
1659 tuple<_Types...>,
Nikolas Klauser669b4452022-02-17 22:53:20 +01001660 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001661 >::type,
1662 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1663 _Tuple1, _Tuples...>
1664{
1665};
1666
1667template <class ..._Tuples> struct __tuple_cat_return;
1668
1669template <class _Tuple0, class ..._Tuples>
1670struct __tuple_cat_return<_Tuple0, _Tuples...>
1671 : public __tuple_cat_return_1<tuple<>,
1672 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1673 _Tuples...>
1674{
1675};
1676
1677template <>
1678struct __tuple_cat_return<>
1679{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001680 typedef _LIBCPP_NODEBUG tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001681};
1682
Marshall Clow2229cee2013-07-22 16:02:19 +00001683inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001684tuple<>
1685tuple_cat()
1686{
1687 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001688}
1689
Howard Hinnantc834c512011-11-29 18:15:50 +00001690template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001691struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001692
Howard Hinnant21376f62010-12-12 23:04:37 +00001693template <class ..._Types, size_t ..._I0, class _Tuple0>
1694struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001695{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001696 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001697 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1698 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1699};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001700
Howard Hinnant21376f62010-12-12 23:04:37 +00001701template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1702struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1703 _Tuple0, _Tuple1, _Tuples...>
1704 : public __tuple_cat_return_ref_imp<
1705 tuple<_Types..., typename __apply_cv<_Tuple0,
1706 typename tuple_element<_I0,
1707 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1708 typename __make_tuple_indices<tuple_size<typename
1709 remove_reference<_Tuple1>::type>::value>::type,
1710 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001711{
Howard Hinnant21376f62010-12-12 23:04:37 +00001712};
1713
1714template <class _Tuple0, class ..._Tuples>
1715struct __tuple_cat_return_ref
1716 : public __tuple_cat_return_ref_imp<tuple<>,
1717 typename __make_tuple_indices<
1718 tuple_size<typename remove_reference<_Tuple0>::type>::value
1719 >::type, _Tuple0, _Tuples...>
1720{
1721};
1722
1723template <class _Types, class _I0, class _J0>
1724struct __tuple_cat;
1725
1726template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001727struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001728{
1729 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001730 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001731 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1732 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1733 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001734 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
David Blaikie699a5e22019-10-28 18:03:59 -07001735 return _VSTD::forward_as_tuple(
1736 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1737 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001738 }
1739
1740 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001741 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001742 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1743 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1744 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001745 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001746 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1747 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001748 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001749 tuple<_Types...,
1750 typename __apply_cv<_Tuple0, typename tuple_element<
1751 _J0, _T0>::type>::type&&...>,
1752 typename __make_tuple_indices<sizeof...(_Types) +
1753 tuple_size<_T0>::value>::type,
1754 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1755 _VSTD::forward_as_tuple(
1756 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1757 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1758 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001759 }
1760};
1761
1762template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001763inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001764typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1765tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1766{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001767 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001768 return __tuple_cat<tuple<>, __tuple_indices<>,
1769 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001770 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1771 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001772}
1773
1774template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001775struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776 : true_type {};
1777
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778template <class _T1, class _T2>
1779template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001780inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001781pair<_T1, _T2>::pair(piecewise_construct_t,
1782 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1783 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001784 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1785 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001786{
1787}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001788
Eric Fiselier8e892c52016-07-18 00:35:56 +00001789#if _LIBCPP_STD_VER > 14
1790template <class _Tp>
Louis Dionne559be102021-09-22 09:35:32 -04001791inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001792
1793#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1794
1795template <class _Fn, class _Tuple, size_t ..._Id>
1796inline _LIBCPP_INLINE_VISIBILITY
1797constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1798 __tuple_indices<_Id...>)
1799_LIBCPP_NOEXCEPT_RETURN(
Nikolas Klausera28f48e2022-04-06 23:10:21 +02001800 _VSTD::__invoke(
Eric Fiselier8e892c52016-07-18 00:35:56 +00001801 _VSTD::forward<_Fn>(__f),
1802 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1803)
1804
1805template <class _Fn, class _Tuple>
1806inline _LIBCPP_INLINE_VISIBILITY
1807constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1808_LIBCPP_NOEXCEPT_RETURN(
1809 _VSTD::__apply_tuple_impl(
1810 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001811 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001812)
1813
1814template <class _Tp, class _Tuple, size_t... _Idx>
1815inline _LIBCPP_INLINE_VISIBILITY
1816constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1817_LIBCPP_NOEXCEPT_RETURN(
1818 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1819)
1820
1821template <class _Tp, class _Tuple>
1822inline _LIBCPP_INLINE_VISIBILITY
1823constexpr _Tp make_from_tuple(_Tuple&& __t)
1824_LIBCPP_NOEXCEPT_RETURN(
1825 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001826 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001827)
1828
1829#undef _LIBCPP_NOEXCEPT_RETURN
1830
1831#endif // _LIBCPP_STD_VER > 14
1832
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001833#endif // !defined(_LIBCPP_CXX03_LANG)
1834
Howard Hinnantc51e1022010-05-11 19:42:16 +00001835_LIBCPP_END_NAMESPACE_STD
1836
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001837#endif // _LIBCPP_TUPLE