blob: 79527cca585394a2416ab305d0be4acd7aa7bdef [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,
Nikolas Klauser7537c9c2022-07-04 01:21:44 +0200485 class = __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000487 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000488 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
489 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000490 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
491 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492 {}
493
494 template <class _Alloc, class _Tuple,
Nikolas Klauser7537c9c2022-07-04 01:21:44 +0200495 class = __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500497 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
499 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000500 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000501 _VSTD::forward<typename tuple_element<_Indx,
502 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503 {}
504
Howard Hinnant0d032d12013-11-06 17:45:43 +0000505 __tuple_impl(const __tuple_impl&) = default;
506 __tuple_impl(__tuple_impl&&) = default;
507
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500508 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000510 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400512 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 }
Hui Xied1637a82022-05-12 13:23:11 +0100514
515 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
516 void swap(const __tuple_impl& __t) const
517 _NOEXCEPT_(__all<__is_nothrow_swappable<const _Tp>::value...>::value)
518 {
519 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...);
520 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000521};
522
Louis Dionne6c0d5342018-07-31 11:56:20 -0400523template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500524_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400525void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
526 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
527}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000528
Louis Dionne6c0d5342018-07-31 11:56:20 -0400529template<class _Dest, class _Source, class ..._Up, 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_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
532 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500533 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400534 ), void(), 0)...);
535}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000536
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000538class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000539{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000540 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000541
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000542 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543
Marshall Clow0abb1042013-07-17 18:25:36 +0000544 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000545 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000546 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000547 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000548 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000549 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000550 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
551 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500553 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554
Louis Dionne574e2e32021-02-10 16:19:50 -0500555 // tuple() constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400556 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500557 _And<
558 _IsImpDefault<_Tp>... // explicit check
559 >::value
560 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400561 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000562 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500563 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
564 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000565
Louis Dionne574e2e32021-02-10 16:19:50 -0500566 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400567 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500568 _And<
569 _IsDefault<_Tp>...,
570 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
571 >::value
572 , int> = 0>
573 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
574 explicit tuple()
575 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
576 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000577
Louis Dionne9ce598d2021-09-08 09:14:43 -0400578 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500579 _And<
580 _IsImpDefault<_Tp>... // explicit check
581 >::value
582 , int> = 0>
583 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
584 tuple(allocator_arg_t, _Alloc const& __a)
585 : __base_(allocator_arg_t(), __a,
586 __tuple_indices<>(), __tuple_types<>(),
587 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
588 __tuple_types<_Tp...>()) {}
589
590 template <class _Alloc,
591 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400592 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500593 _And<
594 _IsDefault<_Tp>...,
595 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
596 >::value
597 , int> = 0>
598 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
599 explicit tuple(allocator_arg_t, _Alloc const& __a)
600 : __base_(allocator_arg_t(), __a,
601 __tuple_indices<>(), __tuple_types<>(),
602 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
603 __tuple_types<_Tp...>()) {}
604
605 // tuple(const T&...) constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400606 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500607 _And<
608 _BoolConstant<sizeof...(_Tp) >= 1>,
609 is_copy_constructible<_Tp>...,
610 is_convertible<const _Tp&, _Tp>... // explicit check
611 >::value
612 , int> = 0>
613 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
614 tuple(const _Tp& ... __t)
615 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
616 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
617 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
618 typename __make_tuple_indices<0>::type(),
619 typename __make_tuple_types<tuple, 0>::type(),
620 __t...
621 ) {}
622
Louis Dionne9ce598d2021-09-08 09:14:43 -0400623 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500624 _And<
625 _BoolConstant<sizeof...(_Tp) >= 1>,
626 is_copy_constructible<_Tp>...,
627 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
628 >::value
629 , int> = 0>
630 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
631 explicit tuple(const _Tp& ... __t)
632 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
633 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
634 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
635 typename __make_tuple_indices<0>::type(),
636 typename __make_tuple_types<tuple, 0>::type(),
637 __t...
638 ) {}
639
Louis Dionne9ce598d2021-09-08 09:14:43 -0400640 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500641 _And<
642 _BoolConstant<sizeof...(_Tp) >= 1>,
643 is_copy_constructible<_Tp>...,
644 is_convertible<const _Tp&, _Tp>... // explicit check
645 >::value
646 , int> = 0>
647 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
648 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
649 : __base_(allocator_arg_t(), __a,
650 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
651 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
652 typename __make_tuple_indices<0>::type(),
653 typename __make_tuple_types<tuple, 0>::type(),
654 __t...
655 ) {}
656
Louis Dionne9ce598d2021-09-08 09:14:43 -0400657 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500658 _And<
659 _BoolConstant<sizeof...(_Tp) >= 1>,
660 is_copy_constructible<_Tp>...,
661 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
662 >::value
663 , int> = 0>
664 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
665 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
666 : __base_(allocator_arg_t(), __a,
667 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
668 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
669 typename __make_tuple_indices<0>::type(),
670 typename __make_tuple_types<tuple, 0>::type(),
671 __t...
672 ) {}
673
674 // tuple(U&& ...) constructors (including allocator_arg_t variants)
675 template <class ..._Up> struct _IsThisTuple : false_type { };
676 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
677
678 template <class ..._Up>
679 struct _EnableUTypesCtor : _And<
680 _BoolConstant<sizeof...(_Tp) >= 1>,
681 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
682 is_constructible<_Tp, _Up>...
683 > { };
684
Louis Dionne9ce598d2021-09-08 09:14:43 -0400685 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500686 _And<
687 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
688 _EnableUTypesCtor<_Up...>,
689 is_convertible<_Up, _Tp>... // explicit check
690 >::value
691 , int> = 0>
692 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
693 tuple(_Up&&... __u)
694 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
695 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
696 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
697 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
698 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
699 _VSTD::forward<_Up>(__u)...) {}
700
Louis Dionne9ce598d2021-09-08 09:14:43 -0400701 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500702 _And<
703 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
704 _EnableUTypesCtor<_Up...>,
705 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
706 >::value
707 , int> = 0>
708 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
709 explicit tuple(_Up&&... __u)
710 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
711 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
712 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
713 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
714 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
715 _VSTD::forward<_Up>(__u)...) {}
716
Louis Dionne9ce598d2021-09-08 09:14:43 -0400717 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500718 _And<
719 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
720 _EnableUTypesCtor<_Up...>,
721 is_convertible<_Up, _Tp>... // explicit check
722 >::value
723 , int> = 0>
724 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
725 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
726 : __base_(allocator_arg_t(), __a,
727 typename __make_tuple_indices<sizeof...(_Up)>::type(),
728 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
729 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
730 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
731 _VSTD::forward<_Up>(__u)...) {}
732
Louis Dionne9ce598d2021-09-08 09:14:43 -0400733 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500734 _And<
735 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
736 _EnableUTypesCtor<_Up...>,
737 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
738 >::value
739 , int> = 0>
740 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
741 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
742 : __base_(allocator_arg_t(), __a,
743 typename __make_tuple_indices<sizeof...(_Up)>::type(),
744 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
745 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
746 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
747 _VSTD::forward<_Up>(__u)...) {}
748
749 // Copy and move constructors (including the allocator_arg_t variants)
750 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000751 tuple(tuple&&) = default;
752
Louis Dionne9ce598d2021-09-08 09:14:43 -0400753 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500754 _And<is_copy_constructible<_Tp>...>::value
755 , int> = 0>
Hui Xied1637a82022-05-12 13:23:11 +0100756 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500757 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
758 : __base_(allocator_arg_t(), __alloc, __t)
759 { }
760
Louis Dionne9ce598d2021-09-08 09:14:43 -0400761 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500762 _And<is_move_constructible<_Tp>...>::value
763 , int> = 0>
Hui Xied1637a82022-05-12 13:23:11 +0100764 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500765 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
766 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
767 { }
768
769 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
Louis Dionne76450ee2022-06-27 09:36:52 -0400770
Hui Xied1637a82022-05-12 13:23:11 +0100771 template <class _OtherTuple, class _DecayedOtherTuple = __uncvref_t<_OtherTuple>, class = void>
772 struct _EnableCtorFromUTypesTuple : false_type {};
773
774 template <class _OtherTuple, class... _Up>
Louis Dionne76450ee2022-06-27 09:36:52 -0400775 struct _EnableCtorFromUTypesTuple<_OtherTuple, tuple<_Up...>,
Hui Xied1637a82022-05-12 13:23:11 +0100776 // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below
777 __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>> : _And<
778 // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor can work.
779 // Otherwise, is_constructible can trigger hard error in those cases https://godbolt.org/z/M94cGdKcE
780 _Not<is_same<_OtherTuple, const tuple&> >,
781 _Not<is_same<_OtherTuple, tuple&&> >,
782 is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,
783 _Lazy<_Or, _BoolConstant<sizeof...(_Tp) != 1>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500784 // _Tp and _Up are 1-element packs - the pack expansions look
785 // weird to avoid tripping up the type traits in degenerate cases
786 _Lazy<_And,
Hui Xied1637a82022-05-12 13:23:11 +0100787 _Not<is_same<_Tp, _Up> >...,
788 _Not<is_convertible<_OtherTuple, _Tp> >...,
789 _Not<is_constructible<_Tp, _OtherTuple> >...
Louis Dionne574e2e32021-02-10 16:19:50 -0500790 >
Hui Xied1637a82022-05-12 13:23:11 +0100791 >
792 > {};
Louis Dionne574e2e32021-02-10 16:19:50 -0500793
Louis Dionne9ce598d2021-09-08 09:14:43 -0400794 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500795 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100796 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500797 is_convertible<const _Up&, _Tp>... // explicit check
798 >::value
799 , int> = 0>
800 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
801 tuple(const tuple<_Up...>& __t)
802 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
803 : __base_(__t)
804 { }
805
Louis Dionne9ce598d2021-09-08 09:14:43 -0400806 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500807 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100808 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500809 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
810 >::value
811 , int> = 0>
812 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
813 explicit tuple(const tuple<_Up...>& __t)
814 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
815 : __base_(__t)
816 { }
817
Louis Dionne9ce598d2021-09-08 09:14:43 -0400818 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500819 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100820 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500821 is_convertible<const _Up&, _Tp>... // explicit check
822 >::value
823 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500824 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500825 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
826 : __base_(allocator_arg_t(), __a, __t)
827 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000828
Louis Dionne9ce598d2021-09-08 09:14:43 -0400829 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500830 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100831 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500832 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
833 >::value
834 , int> = 0>
835 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
836 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
837 : __base_(allocator_arg_t(), __a, __t)
838 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000839
Hui Xied1637a82022-05-12 13:23:11 +0100840#if _LIBCPP_STD_VER > 20
841 // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
842
843 template <class... _Up, enable_if_t<
844 _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
845 _LIBCPP_HIDE_FROM_ABI constexpr
846 explicit(!(is_convertible_v<_Up&, _Tp> && ...))
847 tuple(tuple<_Up...>& __t) : __base_(__t) {}
848
849 template <class _Alloc, 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(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t) : __base_(allocator_arg_t(), __alloc, __t) {}
854#endif // _LIBCPP_STD_VER > 20
855
Louis Dionne574e2e32021-02-10 16:19:50 -0500856 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
Louis Dionne574e2e32021-02-10 16:19:50 -0500857
Louis Dionne9ce598d2021-09-08 09:14:43 -0400858 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500859 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100860 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500861 is_convertible<_Up, _Tp>... // explicit check
862 >::value
863 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000864 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500865 tuple(tuple<_Up...>&& __t)
866 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
867 : __base_(_VSTD::move(__t))
868 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869
Louis Dionne9ce598d2021-09-08 09:14:43 -0400870 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500871 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100872 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500873 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
874 >::value
875 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000876 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500877 explicit tuple(tuple<_Up...>&& __t)
878 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
879 : __base_(_VSTD::move(__t))
880 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000881
Louis Dionne9ce598d2021-09-08 09:14:43 -0400882 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500883 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100884 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500885 is_convertible<_Up, _Tp>... // explicit check
886 >::value
887 , int> = 0>
888 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
889 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
890 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
891 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892
Louis Dionne9ce598d2021-09-08 09:14:43 -0400893 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500894 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100895 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500896 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
897 >::value
898 , int> = 0>
899 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
900 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
901 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
902 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000903
Hui Xied1637a82022-05-12 13:23:11 +0100904#if _LIBCPP_STD_VER > 20
905 // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
Hui Xiea3ac9222022-05-12 13:23:11 +0100906
Hui Xied1637a82022-05-12 13:23:11 +0100907 template <class... _Up, enable_if_t<
908 _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
909 _LIBCPP_HIDE_FROM_ABI constexpr
910 explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
911 tuple(const tuple<_Up...>&& __t) : __base_(std::move(__t)) {}
912
913 template <class _Alloc, 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(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
918 : __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
919#endif // _LIBCPP_STD_VER > 20
920
921 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
922
923 template <template <class...> class Pred, class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
924 struct _CtorPredicateFromPair : false_type{};
925
926 template <template <class...> class Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
927 struct _CtorPredicateFromPair<Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
928 Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >,
929 Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> >
930 > {};
931
932 template <class _Pair>
933 struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair>{};
934
935 template <class _Pair>
936 struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair>{};
937
938 template <class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
939 struct _BothImplicitlyConvertible : false_type{};
940
941 template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
942 struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
943 is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>,
944 is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2>
945 > {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946
Louis Dionne9ce598d2021-09-08 09:14:43 -0400947 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500948 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100949 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
950 _BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500951 >::value
952 , int> = 0>
953 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
954 tuple(const pair<_Up1, _Up2>& __p)
Hui Xied1637a82022-05-12 13:23:11 +0100955 _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -0500956 : __base_(__p)
957 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000958
Louis Dionne9ce598d2021-09-08 09:14:43 -0400959 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500960 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100961 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
962 _Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500963 >::value
964 , int> = 0>
965 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
966 explicit tuple(const pair<_Up1, _Up2>& __p)
Hui Xied1637a82022-05-12 13:23:11 +0100967 _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -0500968 : __base_(__p)
969 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000970
Louis Dionne9ce598d2021-09-08 09:14:43 -0400971 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500972 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100973 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
974 _BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500975 >::value
976 , int> = 0>
977 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
978 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
979 : __base_(allocator_arg_t(), __a, __p)
980 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981
Louis Dionne9ce598d2021-09-08 09:14:43 -0400982 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500983 _And<
Hui Xied1637a82022-05-12 13:23:11 +0100984 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
985 _Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500986 >::value
987 , int> = 0>
988 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
989 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
990 : __base_(allocator_arg_t(), __a, __p)
991 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000992
Hui Xied1637a82022-05-12 13:23:11 +0100993#if _LIBCPP_STD_VER > 20
994 // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
Hui Xie39360e22022-06-23 21:54:23 +0100995
Hui Xied1637a82022-05-12 13:23:11 +0100996 template <class _U1, class _U2, enable_if_t<
997 _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
998 _LIBCPP_HIDE_FROM_ABI constexpr
999 explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
1000 tuple(pair<_U1, _U2>& __p) : __base_(__p) {}
1001
1002 template <class _Alloc, class _U1, class _U2, enable_if_t<
1003 _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>
1004 _LIBCPP_HIDE_FROM_ABI constexpr
1005 explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
1006 tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p) : __base_(allocator_arg_t(), __alloc, __p) {}
1007#endif
1008
1009 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010
Louis Dionne9ce598d2021-09-08 09:14:43 -04001011 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001012 _And<
Hui Xied1637a82022-05-12 13:23:11 +01001013 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1014 _BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001015 >::value
1016 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -04001017 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -05001018 tuple(pair<_Up1, _Up2>&& __p)
Hui Xied1637a82022-05-12 13:23:11 +01001019 _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -05001020 : __base_(_VSTD::move(__p))
1021 { }
1022
Louis Dionne9ce598d2021-09-08 09:14:43 -04001023 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001024 _And<
Hui Xied1637a82022-05-12 13:23:11 +01001025 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1026 _Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001027 >::value
1028 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -04001029 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -05001030 explicit tuple(pair<_Up1, _Up2>&& __p)
Hui Xied1637a82022-05-12 13:23:11 +01001031 _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -05001032 : __base_(_VSTD::move(__p))
1033 { }
1034
Louis Dionne9ce598d2021-09-08 09:14:43 -04001035 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001036 _And<
Hui Xied1637a82022-05-12 13:23:11 +01001037 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1038 _BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001039 >::value
1040 , int> = 0>
1041 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1042 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
1043 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
1044 { }
1045
Louis Dionne9ce598d2021-09-08 09:14:43 -04001046 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001047 _And<
Hui Xied1637a82022-05-12 13:23:11 +01001048 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1049 _Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001050 >::value
1051 , int> = 0>
1052 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1053 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
1054 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
1055 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +00001056
Hui Xied1637a82022-05-12 13:23:11 +01001057#if _LIBCPP_STD_VER > 20
1058 // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
1059
1060 template <class _U1, class _U2, enable_if_t<
1061 _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
1062 _LIBCPP_HIDE_FROM_ABI constexpr
1063 explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
1064 tuple(const pair<_U1, _U2>&& __p) : __base_(std::move(__p)) {}
1065
1066 template <class _Alloc, 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(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
1071 : __base_(allocator_arg_t(), __alloc, std::move(__p)) {}
1072#endif // _LIBCPP_STD_VER > 20
1073
Louis Dionne6c0d5342018-07-31 11:56:20 -04001074 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001075 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001076 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
1077 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +00001078 {
Louis Dionne6c0d5342018-07-31 11:56:20 -04001079 _VSTD::__memberwise_copy_assign(*this, __tuple,
1080 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +00001081 return *this;
1082 }
1083
Hui Xied1637a82022-05-12 13:23:11 +01001084#if _LIBCPP_STD_VER > 20
1085 _LIBCPP_HIDE_FROM_ABI constexpr
1086 const tuple& operator=(tuple const& __tuple) const
1087 requires (_And<is_copy_assignable<const _Tp>...>::value) {
1088 std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
1089 return *this;
1090 }
1091
1092 _LIBCPP_HIDE_FROM_ABI constexpr
1093 const tuple& operator=(tuple&& __tuple) const
1094 requires (_And<is_assignable<const _Tp&, _Tp>...>::value) {
1095 std::__memberwise_forward_assign(*this,
1096 std::move(__tuple),
1097 __tuple_types<_Tp...>(),
1098 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1099 return *this;
1100 }
1101#endif // _LIBCPP_STD_VER > 20
1102
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001103 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001104 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
1105 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +00001106 {
Louis Dionne6c0d5342018-07-31 11:56:20 -04001107 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1108 __tuple_types<_Tp...>(),
1109 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +00001110 return *this;
1111 }
1112
Louis Dionne9ce598d2021-09-08 09:14:43 -04001113 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001114 _And<
1115 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1116 is_assignable<_Tp&, _Up const&>...
1117 >::value
1118 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001119 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001120 tuple& operator=(tuple<_Up...> const& __tuple)
1121 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1122 {
1123 _VSTD::__memberwise_copy_assign(*this, __tuple,
1124 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1125 return *this;
1126 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001127
Louis Dionne9ce598d2021-09-08 09:14:43 -04001128 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001129 _And<
1130 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1131 is_assignable<_Tp&, _Up>...
1132 >::value
1133 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001134 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001135 tuple& operator=(tuple<_Up...>&& __tuple)
1136 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1137 {
1138 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1139 __tuple_types<_Up...>(),
1140 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1141 return *this;
1142 }
1143
Hui Xied1637a82022-05-12 13:23:11 +01001144
1145#if _LIBCPP_STD_VER > 20
1146 template <class... _UTypes, enable_if_t<
1147 _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
1148 is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
1149 _LIBCPP_HIDE_FROM_ABI constexpr
1150 const tuple& operator=(const tuple<_UTypes...>& __u) const {
1151 std::__memberwise_copy_assign(*this,
1152 __u,
1153 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1154 return *this;
1155 }
1156
1157 template <class... _UTypes, enable_if_t<
1158 _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
1159 is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
1160 _LIBCPP_HIDE_FROM_ABI constexpr
1161 const tuple& operator=(tuple<_UTypes...>&& __u) const {
1162 std::__memberwise_forward_assign(*this,
1163 __u,
1164 __tuple_types<_UTypes...>(),
1165 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1166 return *this;
1167 }
1168#endif // _LIBCPP_STD_VER > 20
1169
Louis Dionne76450ee2022-06-27 09:36:52 -04001170 template <template<class...> class Pred, bool _Const,
Hui Xied1637a82022-05-12 13:23:11 +01001171 class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
1172 struct _AssignPredicateFromPair : false_type {};
1173
Louis Dionne76450ee2022-06-27 09:36:52 -04001174 template <template<class...> class Pred, bool _Const,
Hui Xied1637a82022-05-12 13:23:11 +01001175 class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
Louis Dionne76450ee2022-06-27 09:36:52 -04001176 struct _AssignPredicateFromPair<Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > :
Hui Xied1637a82022-05-12 13:23:11 +01001177 _And<Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,
1178 Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> >
1179 > {};
1180
1181 template <bool _Const, class _Pair>
1182 struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};
1183
1184 template <bool _Const, class _Pair>
1185 struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
1186
1187#if _LIBCPP_STD_VER > 20
1188 template <class _U1, class _U2, enable_if_t<
1189 _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
1190 _LIBCPP_HIDE_FROM_ABI constexpr
1191 const tuple& operator=(const pair<_U1, _U2>& __pair) const
1192 noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
1193 std::get<0>(*this) = __pair.first;
1194 std::get<1>(*this) = __pair.second;
1195 return *this;
1196 }
1197
1198 template <class _U1, class _U2, enable_if_t<
1199 _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>
1200 _LIBCPP_HIDE_FROM_ABI constexpr
1201 const tuple& operator=(pair<_U1, _U2>&& __pair) const
1202 noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {
1203 std::get<0>(*this) = std::move(__pair.first);
1204 std::get<1>(*this) = std::move(__pair.second);
1205 return *this;
1206 }
1207#endif // _LIBCPP_STD_VER > 20
1208
1209 template<class _Up1, class _Up2, __enable_if_t<
1210 _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value
Louis Dionne6c0d5342018-07-31 11:56:20 -04001211 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001212 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001213 tuple& operator=(pair<_Up1, _Up2> const& __pair)
Hui Xied1637a82022-05-12 13:23:11 +01001214 _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value))
Louis Dionne6c0d5342018-07-31 11:56:20 -04001215 {
1216 _VSTD::get<0>(*this) = __pair.first;
1217 _VSTD::get<1>(*this) = __pair.second;
1218 return *this;
1219 }
1220
Hui Xied1637a82022-05-12 13:23:11 +01001221 template<class _Up1, class _Up2, __enable_if_t<
1222 _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value
Louis Dionne6c0d5342018-07-31 11:56:20 -04001223 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001224 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001225 tuple& operator=(pair<_Up1, _Up2>&& __pair)
Hui Xied1637a82022-05-12 13:23:11 +01001226 _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value))
Louis Dionne6c0d5342018-07-31 11:56:20 -04001227 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001228 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1229 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001230 return *this;
1231 }
1232
1233 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001234 template<class _Up, size_t _Np, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001235 _And<
1236 _BoolConstant<_Np == sizeof...(_Tp)>,
1237 is_assignable<_Tp&, _Up const&>...
1238 >::value
1239 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001240 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001241 tuple& operator=(array<_Up, _Np> const& __array)
1242 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1243 {
1244 _VSTD::__memberwise_copy_assign(*this, __array,
1245 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1246 return *this;
1247 }
1248
1249 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001250 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001251 _And<
1252 _BoolConstant<_Np == sizeof...(_Tp)>,
1253 is_assignable<_Tp&, _Up>...
1254 >::value
1255 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001256 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001257 tuple& operator=(array<_Up, _Np>&& __array)
1258 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1259 {
1260 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1261 __tuple_types<_If<true, _Up, _Tp>...>(),
1262 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1263 return *this;
1264 }
1265
1266 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001267 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001268 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001269 {__base_.swap(__t.__base_);}
Hui Xied1637a82022-05-12 13:23:11 +01001270
1271#if _LIBCPP_STD_VER > 20
1272 _LIBCPP_HIDE_FROM_ABI constexpr
1273 void swap(const tuple& __t) const noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
1274 __base_.swap(__t.__base_);
1275 }
1276#endif // _LIBCPP_STD_VER > 20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277};
1278
1279template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001280class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281{
1282public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001283 _LIBCPP_INLINE_VISIBILITY constexpr
1284 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001286 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001287 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001288 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001289 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001290 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001291 template <class _Up>
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(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001294 template <class _Alloc, class _Up>
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&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001297 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001298 void swap(tuple&) _NOEXCEPT {}
Hui Xied1637a82022-05-12 13:23:11 +01001299#if _LIBCPP_STD_VER > 20
1300 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
1301#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001302};
1303
Joe Loserd9b3d972022-03-12 10:46:57 -05001304#if _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001305template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1306 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1307struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1308 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1309};
1310
1311template <class... _TTypes, class... _UTypes>
1312 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1313struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1314 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1315};
Joe Loserd9b3d972022-03-12 10:46:57 -05001316#endif // _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001317
1318#if _LIBCPP_STD_VER > 14
Louis Dionne616da2a2019-08-12 18:30:31 +00001319template <class ..._Tp>
1320tuple(_Tp...) -> tuple<_Tp...>;
1321template <class _Tp1, class _Tp2>
1322tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1323template <class _Alloc, class ..._Tp>
1324tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1325template <class _Alloc, class _Tp1, class _Tp2>
1326tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1327template <class _Alloc, class ..._Tp>
1328tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001329#endif
1330
Howard Hinnantc51e1022010-05-11 19:42:16 +00001331template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001332inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Nikolas Klauser7537c9c2022-07-04 01:21:44 +02001333__enable_if_t<__all<__is_swappable<_Tp>::value...>::value, void>
Howard Hinnant89ef1212011-05-27 19:08:18 +00001334swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1335 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1336 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337
Hui Xied1637a82022-05-12 13:23:11 +01001338#if _LIBCPP_STD_VER > 20
1339template <class... _Tp>
1340_LIBCPP_HIDE_FROM_ABI constexpr
1341enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
1342swap(const tuple<_Tp...>& __lhs, const tuple<_Tp...>& __rhs)
1343 noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
1344 __lhs.swap(__rhs);
1345}
1346#endif
1347
Howard Hinnantc51e1022010-05-11 19:42:16 +00001348// get
1349
1350template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001351inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001352typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001353get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001354{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001355 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001356 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001357}
1358
1359template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001360inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001361const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001362get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001364 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001365 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001366}
1367
Howard Hinnant22e97242010-11-17 19:52:17 +00001368template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001369inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001370typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001371get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001372{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001373 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001374 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001375 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001376}
1377
Eric Fiselier6dea8092015-12-18 00:36:55 +00001378template <size_t _Ip, class ..._Tp>
1379inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1380const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1381get(const tuple<_Tp...>&& __t) _NOEXCEPT
1382{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001383 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001384 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001385 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001386}
1387
Marshall Clow15b02e02013-07-13 02:54:05 +00001388#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001389
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001390namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001391
Louis Dionne7dd28aa2021-07-20 11:46:05 -04001392static constexpr size_t __not_found = static_cast<size_t>(-1);
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001393static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001394
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001395inline _LIBCPP_INLINE_VISIBILITY
1396constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1397 return !__matches ? __res :
1398 (__res == __not_found ? __curr_i : __ambiguous);
1399}
Marshall Clow15b02e02013-07-13 02:54:05 +00001400
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001401template <size_t _Nx>
1402inline _LIBCPP_INLINE_VISIBILITY
1403constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1404 return __i == _Nx ? __not_found :
1405 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1406}
1407
1408template <class _T1, class ..._Args>
1409struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001410 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001411 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001412 static_assert(value != __not_found, "type not found in type list" );
1413 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001414};
1415
Eric Fiselier8087d302016-07-02 03:46:08 +00001416template <class _T1>
1417struct __find_exactly_one_checked<_T1> {
1418 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1419};
1420
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001421} // namespace __find_detail
Marshall Clow15b02e02013-07-13 02:54:05 +00001422
1423template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001424struct __find_exactly_one_t
1425 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1426};
Marshall Clow15b02e02013-07-13 02:54:05 +00001427
1428template <class _T1, class... _Args>
1429inline _LIBCPP_INLINE_VISIBILITY
1430constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1431{
1432 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1433}
1434
1435template <class _T1, class... _Args>
1436inline _LIBCPP_INLINE_VISIBILITY
1437constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1438{
1439 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1440}
1441
1442template <class _T1, class... _Args>
1443inline _LIBCPP_INLINE_VISIBILITY
1444constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1445{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001446 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001447}
1448
Eric Fiselier6dea8092015-12-18 00:36:55 +00001449template <class _T1, class... _Args>
1450inline _LIBCPP_INLINE_VISIBILITY
1451constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1452{
1453 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1454}
1455
Marshall Clow15b02e02013-07-13 02:54:05 +00001456#endif
1457
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458// tie
1459
1460template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001461inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001463tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464{
1465 return tuple<_Tp&...>(__t...);
1466}
1467
1468template <class _Up>
1469struct __ignore_t
1470{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001471 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001472 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1473 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474};
1475
Eric Fiselier24e70262017-02-06 01:25:31 +00001476namespace {
Louis Dionne559be102021-09-22 09:35:32 -04001477 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001478} // namespace
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479
Howard Hinnantc51e1022010-05-11 19:42:16 +00001480template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001481inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001482tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001483make_tuple(_Tp&&... __t)
1484{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001485 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486}
1487
Howard Hinnant3d203a32010-08-19 18:59:38 +00001488template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001489inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1490tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001491forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001492{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001493 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001494}
1495
Howard Hinnantc834c512011-11-29 18:15:50 +00001496template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001497struct __tuple_equal
1498{
1499 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001500 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501 bool operator()(const _Tp& __x, const _Up& __y)
1502 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001503 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504 }
1505};
1506
1507template <>
1508struct __tuple_equal<0>
1509{
1510 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001511 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512 bool operator()(const _Tp&, const _Up&)
1513 {
1514 return true;
1515 }
1516};
1517
1518template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001519inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520bool
1521operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1522{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001523 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1525}
1526
Joe Loserd9b3d972022-03-12 10:46:57 -05001527#if _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001528
1529// operator<=>
1530
1531template <class ..._Tp, class ..._Up, size_t ..._Is>
1532_LIBCPP_HIDE_FROM_ABI constexpr
1533auto
1534__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1535 common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1536 static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1537 return __result;
1538}
1539
1540template <class ..._Tp, class ..._Up>
1541requires (sizeof...(_Tp) == sizeof...(_Up))
1542_LIBCPP_HIDE_FROM_ABI constexpr
1543common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1544operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1545{
1546 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1547}
1548
Joe Loserd9b3d972022-03-12 10:46:57 -05001549#else // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001550
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001552inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001553bool
1554operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1555{
1556 return !(__x == __y);
1557}
1558
Howard Hinnantc834c512011-11-29 18:15:50 +00001559template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560struct __tuple_less
1561{
1562 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001563 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001564 bool operator()(const _Tp& __x, const _Up& __y)
1565 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001566 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1567 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1568 return true;
1569 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1570 return false;
1571 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001572 }
1573};
1574
1575template <>
1576struct __tuple_less<0>
1577{
1578 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001579 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580 bool operator()(const _Tp&, const _Up&)
1581 {
1582 return false;
1583 }
1584};
1585
1586template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001587inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001588bool
1589operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1590{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001591 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1593}
1594
1595template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001596inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001597bool
1598operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1599{
1600 return __y < __x;
1601}
1602
1603template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001604inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001605bool
1606operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1607{
1608 return !(__x < __y);
1609}
1610
1611template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001612inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001613bool
1614operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1615{
1616 return !(__y < __x);
1617}
1618
Joe Loserd9b3d972022-03-12 10:46:57 -05001619#endif // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001620
Howard Hinnantc51e1022010-05-11 19:42:16 +00001621// tuple_cat
1622
Howard Hinnant6256ee72010-12-11 20:47:50 +00001623template <class _Tp, class _Up> struct __tuple_cat_type;
1624
1625template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001626struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001627{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001628 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001629};
1630
1631template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1632struct __tuple_cat_return_1
1633{
1634};
1635
1636template <class ..._Types, class _Tuple0>
1637struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1638{
Nikolas Klauser669b4452022-02-17 22:53:20 +01001639 using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
1640 tuple<_Types...>,
1641 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
1642 >::type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001643};
1644
1645template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1646struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1647 : public __tuple_cat_return_1<
1648 typename __tuple_cat_type<
1649 tuple<_Types...>,
Nikolas Klauser669b4452022-02-17 22:53:20 +01001650 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001651 >::type,
1652 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1653 _Tuple1, _Tuples...>
1654{
1655};
1656
1657template <class ..._Tuples> struct __tuple_cat_return;
1658
1659template <class _Tuple0, class ..._Tuples>
1660struct __tuple_cat_return<_Tuple0, _Tuples...>
1661 : public __tuple_cat_return_1<tuple<>,
1662 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1663 _Tuples...>
1664{
1665};
1666
1667template <>
1668struct __tuple_cat_return<>
1669{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001670 typedef _LIBCPP_NODEBUG tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001671};
1672
Marshall Clow2229cee2013-07-22 16:02:19 +00001673inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001674tuple<>
1675tuple_cat()
1676{
1677 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001678}
1679
Howard Hinnantc834c512011-11-29 18:15:50 +00001680template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001681struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001682
Howard Hinnant21376f62010-12-12 23:04:37 +00001683template <class ..._Types, size_t ..._I0, class _Tuple0>
1684struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001685{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001686 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001687 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1688 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1689};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001690
Howard Hinnant21376f62010-12-12 23:04:37 +00001691template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1692struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1693 _Tuple0, _Tuple1, _Tuples...>
1694 : public __tuple_cat_return_ref_imp<
1695 tuple<_Types..., typename __apply_cv<_Tuple0,
1696 typename tuple_element<_I0,
1697 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1698 typename __make_tuple_indices<tuple_size<typename
1699 remove_reference<_Tuple1>::type>::value>::type,
1700 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001701{
Howard Hinnant21376f62010-12-12 23:04:37 +00001702};
1703
1704template <class _Tuple0, class ..._Tuples>
1705struct __tuple_cat_return_ref
1706 : public __tuple_cat_return_ref_imp<tuple<>,
1707 typename __make_tuple_indices<
1708 tuple_size<typename remove_reference<_Tuple0>::type>::value
1709 >::type, _Tuple0, _Tuples...>
1710{
1711};
1712
1713template <class _Types, class _I0, class _J0>
1714struct __tuple_cat;
1715
1716template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001717struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001718{
1719 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001720 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001721 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1722 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1723 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001724 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
David Blaikie699a5e22019-10-28 18:03:59 -07001725 return _VSTD::forward_as_tuple(
1726 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1727 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001728 }
1729
1730 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001731 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001732 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1733 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1734 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001735 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001736 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1737 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001738 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001739 tuple<_Types...,
1740 typename __apply_cv<_Tuple0, typename tuple_element<
1741 _J0, _T0>::type>::type&&...>,
1742 typename __make_tuple_indices<sizeof...(_Types) +
1743 tuple_size<_T0>::value>::type,
1744 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1745 _VSTD::forward_as_tuple(
1746 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1747 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1748 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001749 }
1750};
1751
1752template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001753inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001754typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1755tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1756{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001757 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001758 return __tuple_cat<tuple<>, __tuple_indices<>,
1759 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001760 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1761 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001762}
1763
1764template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001765struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001766 : true_type {};
1767
Howard Hinnantc51e1022010-05-11 19:42:16 +00001768template <class _T1, class _T2>
1769template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001770inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001771pair<_T1, _T2>::pair(piecewise_construct_t,
1772 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1773 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001774 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1775 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776{
1777}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778
Eric Fiselier8e892c52016-07-18 00:35:56 +00001779#if _LIBCPP_STD_VER > 14
1780template <class _Tp>
Louis Dionne559be102021-09-22 09:35:32 -04001781inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001782
1783#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1784
1785template <class _Fn, class _Tuple, size_t ..._Id>
1786inline _LIBCPP_INLINE_VISIBILITY
1787constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1788 __tuple_indices<_Id...>)
1789_LIBCPP_NOEXCEPT_RETURN(
Nikolas Klausera28f48e2022-04-06 23:10:21 +02001790 _VSTD::__invoke(
Eric Fiselier8e892c52016-07-18 00:35:56 +00001791 _VSTD::forward<_Fn>(__f),
1792 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1793)
1794
1795template <class _Fn, class _Tuple>
1796inline _LIBCPP_INLINE_VISIBILITY
1797constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1798_LIBCPP_NOEXCEPT_RETURN(
1799 _VSTD::__apply_tuple_impl(
1800 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001801 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001802)
1803
1804template <class _Tp, class _Tuple, size_t... _Idx>
1805inline _LIBCPP_INLINE_VISIBILITY
1806constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1807_LIBCPP_NOEXCEPT_RETURN(
1808 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1809)
1810
1811template <class _Tp, class _Tuple>
1812inline _LIBCPP_INLINE_VISIBILITY
1813constexpr _Tp make_from_tuple(_Tuple&& __t)
1814_LIBCPP_NOEXCEPT_RETURN(
1815 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001816 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001817)
1818
1819#undef _LIBCPP_NOEXCEPT_RETURN
1820
1821#endif // _LIBCPP_STD_VER > 14
1822
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001823#endif // !defined(_LIBCPP_CXX03_LANG)
1824
Howard Hinnantc51e1022010-05-11 19:42:16 +00001825_LIBCPP_END_NAMESPACE_STD
1826
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001827#endif // _LIBCPP_TUPLE