blob: d0c159249ede911c78bada146bb7ae7c05bb2610 [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 Xiea3ac9222022-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 Xiea3ac9222022-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 Xiea3ac9222022-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 Xiea3ac9222022-05-12 13:23:11 +010058 template<class Alloc, class... UTypes>
59 constexpr explicit(see-below)
60 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 Xiea3ac9222022-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 Xiea3ac9222022-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 Xiea3ac9222022-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 Xiea3ac9222022-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 Xiea3ac9222022-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 Xiea3ac9222022-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 Xiea3ac9222022-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 Xiea3ac9222022-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 Xiea3ac9222022-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 Xiea3ac9222022-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
Nikolas Klausera0e0edb2022-06-16 22:43:46 +0200222// standard-mandated includes
223#include <compare>
224
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000225#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500226# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000227#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228
229_LIBCPP_BEGIN_NAMESPACE_STD
230
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000231#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000232
Marshall Clowf50d66f2014-03-03 06:18:11 +0000233
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234// __tuple_leaf
235
Eric Fiselierf7394302015-06-13 07:08:02 +0000236template <size_t _Ip, class _Hp,
237 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000238 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239class __tuple_leaf;
240
241template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500242inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000244 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245{
246 swap(__x.get(), __y.get());
247}
248
Hui Xiea3ac9222022-05-12 13:23:11 +0100249template <size_t _Ip, class _Hp, bool _Ep>
250_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
251void swap(const __tuple_leaf<_Ip, _Hp, _Ep>& __x, const __tuple_leaf<_Ip, _Hp, _Ep>& __y)
252 _NOEXCEPT_(__is_nothrow_swappable<const _Hp>::value) {
253 swap(__x.get(), __y.get());
254}
255
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256template <size_t _Ip, class _Hp, bool>
257class __tuple_leaf
258{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000259 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260
Eric Fiselierca8bba12016-07-20 02:57:39 +0000261 template <class _Tp>
262 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000263#if __has_keyword(__reference_binds_to_temporary)
264 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000265#else
266 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000267#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000268 }
269
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500270 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271 __tuple_leaf& operator=(const __tuple_leaf&);
272public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500273 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000274 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 {static_assert(!is_reference<_Hp>::value,
276 "Attempted to default construct a reference element in a tuple");}
277
278 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500279 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000281 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 {static_assert(!is_reference<_Hp>::value,
283 "Attempted to default construct a reference element in a tuple");}
284
285 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500286 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000288 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289 {static_assert(!is_reference<_Hp>::value,
290 "Attempted to default construct a reference element in a tuple");}
291
292 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500293 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000295 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296 {static_assert(!is_reference<_Hp>::value,
297 "Attempted to default construct a reference element in a tuple");}
298
Howard Hinnant693fc212010-09-27 17:54:17 +0000299 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400300 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000301 _And<
302 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
303 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000304 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000305 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000306 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000307 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000308 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000309 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000310 {static_assert(__can_bind_reference<_Tp&&>(),
311 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312
313 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500314 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000316 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000317 {static_assert(__can_bind_reference<_Tp&&>(),
318 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000319
320 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500321 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000322 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000323 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000324 {static_assert(!is_reference<_Hp>::value,
325 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326
327 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500328 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000330 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000331 {static_assert(!is_reference<_Hp>::value,
332 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000333
Marshall Clow47fcee52014-04-21 23:48:09 +0000334 __tuple_leaf(const __tuple_leaf& __t) = default;
335 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500337 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000338 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000340 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341 return 0;
342 }
343
Hui Xiea3ac9222022-05-12 13:23:11 +0100344 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
345 int swap(const __tuple_leaf& __t) const _NOEXCEPT_(__is_nothrow_swappable<const __tuple_leaf>::value) {
346 _VSTD::swap(*this, __t);
347 return 0;
348 }
349
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000350 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
351 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352};
353
354template <size_t _Ip, class _Hp>
355class __tuple_leaf<_Ip, _Hp, true>
356 : private _Hp
357{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500358 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359 __tuple_leaf& operator=(const __tuple_leaf&);
360public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500361 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000362 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363
364 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500365 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
367
368 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500369 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
371 : _Hp(allocator_arg_t(), __a) {}
372
373 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500374 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
376 : _Hp(__a) {}
377
Howard Hinnant693fc212010-09-27 17:54:17 +0000378 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400379 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000380 _And<
381 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
382 is_constructible<_Hp, _Tp>
383 >::value
384 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000385 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000386 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000387 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000388 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389
390 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500391 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000393 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394
395 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500396 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000398 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399
400 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500401 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000403 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000405 __tuple_leaf(__tuple_leaf const &) = default;
406 __tuple_leaf(__tuple_leaf &&) = default;
407
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500408 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000409 int
410 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000412 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413 return 0;
414 }
415
Hui Xiea3ac9222022-05-12 13:23:11 +0100416 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
417 int swap(const __tuple_leaf& __rhs) const _NOEXCEPT_(__is_nothrow_swappable<const __tuple_leaf>::value) {
418 _VSTD::swap(*this, __rhs);
419 return 0;
420 }
421
Marshall Clow2229cee2013-07-22 16:02:19 +0000422 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
423 _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 +0000424};
425
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000426template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500427_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000428void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429
Marshall Clowc470eae2014-10-15 10:33:02 +0000430template <class _Tp>
431struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000432
Marshall Clowc470eae2014-10-15 10:33:02 +0000433template <class ..._Tp>
434struct __all_default_constructible<__tuple_types<_Tp...>>
435 : __all<is_default_constructible<_Tp>::value...>
436{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000437
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438// __tuple_impl
439
440template<class _Indx, class ..._Tp> struct __tuple_impl;
441
442template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000443struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444 : public __tuple_leaf<_Indx, _Tp>...
445{
Howard Hinnant38469632012-07-06 20:39:45 +0000446 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500447 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000448 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000449
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450 template <size_t ..._Uf, class ..._Tf,
451 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000452 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000453 explicit
454 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
455 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000456 _Up&&... __u)
457 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
458 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000459 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460 __tuple_leaf<_Ul, _Tl>()...
461 {}
462
463 template <class _Alloc, size_t ..._Uf, class ..._Tf,
464 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500465 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466 explicit
467 __tuple_impl(allocator_arg_t, const _Alloc& __a,
468 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
469 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
470 _Up&&... __u) :
471 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000472 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
474 {}
475
476 template <class _Tuple,
477 class = typename enable_if
478 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000479 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480 >::type
481 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000482 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000483 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
484 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000485 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
486 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487 {}
488
489 template <class _Alloc, class _Tuple,
490 class = typename enable_if
491 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000492 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493 >::type
494 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500495 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
497 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000498 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000499 _VSTD::forward<typename tuple_element<_Indx,
500 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 {}
502
Howard Hinnant0d032d12013-11-06 17:45:43 +0000503 __tuple_impl(const __tuple_impl&) = default;
504 __tuple_impl(__tuple_impl&&) = default;
505
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500506 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000507 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000508 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400510 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511 }
Hui Xiea3ac9222022-05-12 13:23:11 +0100512
513 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
514 void swap(const __tuple_impl& __t) const
515 _NOEXCEPT_(__all<__is_nothrow_swappable<const _Tp>::value...>::value)
516 {
517 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...);
518 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519};
520
Louis Dionne6c0d5342018-07-31 11:56:20 -0400521template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500522_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400523void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
524 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
525}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000526
Louis Dionne6c0d5342018-07-31 11:56:20 -0400527template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500528_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400529void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
530 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500531 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400532 ), void(), 0)...);
533}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000534
Howard Hinnantc51e1022010-05-11 19:42:16 +0000535template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000536class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000538 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000539
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000540 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000541
Marshall Clow0abb1042013-07-17 18:25:36 +0000542 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000543 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
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 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const 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 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000548 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
549 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500551 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552
Louis Dionne574e2e32021-02-10 16:19:50 -0500553 // tuple() constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400554 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500555 _And<
556 _IsImpDefault<_Tp>... // explicit check
557 >::value
558 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400559 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000560 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500561 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
562 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000563
Louis Dionne574e2e32021-02-10 16:19:50 -0500564 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400565 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500566 _And<
567 _IsDefault<_Tp>...,
568 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
569 >::value
570 , int> = 0>
571 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
572 explicit tuple()
573 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
574 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000575
Louis Dionne9ce598d2021-09-08 09:14:43 -0400576 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500577 _And<
578 _IsImpDefault<_Tp>... // explicit check
579 >::value
580 , int> = 0>
581 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
582 tuple(allocator_arg_t, _Alloc const& __a)
583 : __base_(allocator_arg_t(), __a,
584 __tuple_indices<>(), __tuple_types<>(),
585 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
586 __tuple_types<_Tp...>()) {}
587
588 template <class _Alloc,
589 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400590 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500591 _And<
592 _IsDefault<_Tp>...,
593 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
594 >::value
595 , int> = 0>
596 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
597 explicit tuple(allocator_arg_t, _Alloc const& __a)
598 : __base_(allocator_arg_t(), __a,
599 __tuple_indices<>(), __tuple_types<>(),
600 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
601 __tuple_types<_Tp...>()) {}
602
603 // tuple(const T&...) constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400604 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500605 _And<
606 _BoolConstant<sizeof...(_Tp) >= 1>,
607 is_copy_constructible<_Tp>...,
608 is_convertible<const _Tp&, _Tp>... // explicit check
609 >::value
610 , int> = 0>
611 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
612 tuple(const _Tp& ... __t)
613 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
614 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
615 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
616 typename __make_tuple_indices<0>::type(),
617 typename __make_tuple_types<tuple, 0>::type(),
618 __t...
619 ) {}
620
Louis Dionne9ce598d2021-09-08 09:14:43 -0400621 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500622 _And<
623 _BoolConstant<sizeof...(_Tp) >= 1>,
624 is_copy_constructible<_Tp>...,
625 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
626 >::value
627 , int> = 0>
628 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
629 explicit tuple(const _Tp& ... __t)
630 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
631 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
632 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
633 typename __make_tuple_indices<0>::type(),
634 typename __make_tuple_types<tuple, 0>::type(),
635 __t...
636 ) {}
637
Louis Dionne9ce598d2021-09-08 09:14:43 -0400638 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500639 _And<
640 _BoolConstant<sizeof...(_Tp) >= 1>,
641 is_copy_constructible<_Tp>...,
642 is_convertible<const _Tp&, _Tp>... // explicit check
643 >::value
644 , int> = 0>
645 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
646 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
647 : __base_(allocator_arg_t(), __a,
648 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
649 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
650 typename __make_tuple_indices<0>::type(),
651 typename __make_tuple_types<tuple, 0>::type(),
652 __t...
653 ) {}
654
Louis Dionne9ce598d2021-09-08 09:14:43 -0400655 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500656 _And<
657 _BoolConstant<sizeof...(_Tp) >= 1>,
658 is_copy_constructible<_Tp>...,
659 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
660 >::value
661 , int> = 0>
662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
663 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
664 : __base_(allocator_arg_t(), __a,
665 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
666 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
667 typename __make_tuple_indices<0>::type(),
668 typename __make_tuple_types<tuple, 0>::type(),
669 __t...
670 ) {}
671
672 // tuple(U&& ...) constructors (including allocator_arg_t variants)
673 template <class ..._Up> struct _IsThisTuple : false_type { };
674 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
675
676 template <class ..._Up>
677 struct _EnableUTypesCtor : _And<
678 _BoolConstant<sizeof...(_Tp) >= 1>,
679 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
680 is_constructible<_Tp, _Up>...
681 > { };
682
Louis Dionne9ce598d2021-09-08 09:14:43 -0400683 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500684 _And<
685 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
686 _EnableUTypesCtor<_Up...>,
687 is_convertible<_Up, _Tp>... // explicit check
688 >::value
689 , int> = 0>
690 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
691 tuple(_Up&&... __u)
692 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
693 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
694 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
695 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
696 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
697 _VSTD::forward<_Up>(__u)...) {}
698
Louis Dionne9ce598d2021-09-08 09:14:43 -0400699 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500700 _And<
701 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
702 _EnableUTypesCtor<_Up...>,
703 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
704 >::value
705 , int> = 0>
706 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
707 explicit tuple(_Up&&... __u)
708 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
709 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
710 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
711 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
712 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
713 _VSTD::forward<_Up>(__u)...) {}
714
Louis Dionne9ce598d2021-09-08 09:14:43 -0400715 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500716 _And<
717 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
718 _EnableUTypesCtor<_Up...>,
719 is_convertible<_Up, _Tp>... // explicit check
720 >::value
721 , int> = 0>
722 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
723 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
724 : __base_(allocator_arg_t(), __a,
725 typename __make_tuple_indices<sizeof...(_Up)>::type(),
726 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
727 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
728 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
729 _VSTD::forward<_Up>(__u)...) {}
730
Louis Dionne9ce598d2021-09-08 09:14:43 -0400731 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500732 _And<
733 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
734 _EnableUTypesCtor<_Up...>,
735 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
736 >::value
737 , int> = 0>
738 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
739 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
740 : __base_(allocator_arg_t(), __a,
741 typename __make_tuple_indices<sizeof...(_Up)>::type(),
742 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
743 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
744 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
745 _VSTD::forward<_Up>(__u)...) {}
746
747 // Copy and move constructors (including the allocator_arg_t variants)
748 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000749 tuple(tuple&&) = default;
750
Louis Dionne9ce598d2021-09-08 09:14:43 -0400751 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500752 _And<is_copy_constructible<_Tp>...>::value
753 , int> = 0>
Hui Xiea3ac9222022-05-12 13:23:11 +0100754 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500755 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
756 : __base_(allocator_arg_t(), __alloc, __t)
757 { }
758
Louis Dionne9ce598d2021-09-08 09:14:43 -0400759 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500760 _And<is_move_constructible<_Tp>...>::value
761 , int> = 0>
Hui Xiea3ac9222022-05-12 13:23:11 +0100762 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500763 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
764 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
765 { }
766
767 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
Hui Xiea3ac9222022-05-12 13:23:11 +0100768
769 template <class _OtherTuple, class _DecayedOtherTuple = __uncvref_t<_OtherTuple>, class = void>
770 struct _EnableCtorFromUTypesTuple : false_type {};
771
772 template <class _OtherTuple, class... _Up>
773 struct _EnableCtorFromUTypesTuple<_OtherTuple, tuple<_Up...>,
774 // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below
775 __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>> : _And<
776 // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor can work.
777 // Otherwise, is_constructible can trigger hard error in those cases https://godbolt.org/z/M94cGdKcE
778 _Not<is_same<_OtherTuple, const tuple&> >,
779 _Not<is_same<_OtherTuple, tuple&&> >,
780 is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >...,
781 _Lazy<_Or, _BoolConstant<sizeof...(_Tp) != 1>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500782 // _Tp and _Up are 1-element packs - the pack expansions look
783 // weird to avoid tripping up the type traits in degenerate cases
784 _Lazy<_And,
Hui Xiea3ac9222022-05-12 13:23:11 +0100785 _Not<is_same<_Tp, _Up> >...,
786 _Not<is_convertible<_OtherTuple, _Tp> >...,
787 _Not<is_constructible<_Tp, _OtherTuple> >...
Louis Dionne574e2e32021-02-10 16:19:50 -0500788 >
Hui Xiea3ac9222022-05-12 13:23:11 +0100789 >
790 > {};
Louis Dionne574e2e32021-02-10 16:19:50 -0500791
Louis Dionne9ce598d2021-09-08 09:14:43 -0400792 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500793 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100794 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500795 is_convertible<const _Up&, _Tp>... // explicit check
796 >::value
797 , int> = 0>
798 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
799 tuple(const tuple<_Up...>& __t)
800 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
801 : __base_(__t)
802 { }
803
Louis Dionne9ce598d2021-09-08 09:14:43 -0400804 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500805 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100806 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500807 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
808 >::value
809 , int> = 0>
810 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
811 explicit tuple(const tuple<_Up...>& __t)
812 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
813 : __base_(__t)
814 { }
815
Louis Dionne9ce598d2021-09-08 09:14:43 -0400816 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500817 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100818 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500819 is_convertible<const _Up&, _Tp>... // explicit check
820 >::value
821 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500822 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500823 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
824 : __base_(allocator_arg_t(), __a, __t)
825 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000826
Louis Dionne9ce598d2021-09-08 09:14:43 -0400827 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500828 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100829 _EnableCtorFromUTypesTuple<const tuple<_Up...>&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500830 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
831 >::value
832 , int> = 0>
833 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
834 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
835 : __base_(allocator_arg_t(), __a, __t)
836 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000837
Hui Xiea3ac9222022-05-12 13:23:11 +0100838#if _LIBCPP_STD_VER > 20
839 // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
840
841 template <class... _Up, enable_if_t<
842 _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
843 _LIBCPP_HIDE_FROM_ABI constexpr
844 explicit(!(is_convertible_v<_Up&, _Tp> && ...))
845 tuple(tuple<_Up...>& __t) : __base_(__t) {}
846
847 template <class _Alloc, class... _Up, enable_if_t<
848 _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
849 _LIBCPP_HIDE_FROM_ABI constexpr
850 explicit(!(is_convertible_v<_Up&, _Tp> && ...))
851 tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t) : __base_(allocator_arg_t(), __alloc, __t) {}
852#endif // _LIBCPP_STD_VER > 20
853
Louis Dionne574e2e32021-02-10 16:19:50 -0500854 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
Louis Dionne574e2e32021-02-10 16:19:50 -0500855
Louis Dionne9ce598d2021-09-08 09:14:43 -0400856 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500857 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100858 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500859 is_convertible<_Up, _Tp>... // explicit check
860 >::value
861 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000862 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500863 tuple(tuple<_Up...>&& __t)
864 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
865 : __base_(_VSTD::move(__t))
866 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867
Louis Dionne9ce598d2021-09-08 09:14:43 -0400868 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500869 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100870 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500871 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
872 >::value
873 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000874 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500875 explicit tuple(tuple<_Up...>&& __t)
876 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
877 : __base_(_VSTD::move(__t))
878 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000879
Louis Dionne9ce598d2021-09-08 09:14:43 -0400880 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500881 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100882 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500883 is_convertible<_Up, _Tp>... // explicit check
884 >::value
885 , int> = 0>
886 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
887 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
888 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
889 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890
Louis Dionne9ce598d2021-09-08 09:14:43 -0400891 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500892 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100893 _EnableCtorFromUTypesTuple<tuple<_Up...>&&>,
Louis Dionne574e2e32021-02-10 16:19:50 -0500894 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
895 >::value
896 , int> = 0>
897 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
898 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
899 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
900 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000901
Hui Xiea3ac9222022-05-12 13:23:11 +0100902#if _LIBCPP_STD_VER > 20
903 // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
Howard Hinnant65704d02012-04-01 23:10:42 +0000904
Hui Xiea3ac9222022-05-12 13:23:11 +0100905 template <class... _Up, enable_if_t<
906 _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
907 _LIBCPP_HIDE_FROM_ABI constexpr
908 explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
909 tuple(const tuple<_Up...>&& __t) : __base_(std::move(__t)) {}
910
911 template <class _Alloc, class... _Up, enable_if_t<
912 _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
913 _LIBCPP_HIDE_FROM_ABI constexpr
914 explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
915 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
916 : __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
917#endif // _LIBCPP_STD_VER > 20
918
919 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
920
921 template <template <class...> class Pred, class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
922 struct _CtorPredicateFromPair : false_type{};
923
924 template <template <class...> class Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
925 struct _CtorPredicateFromPair<Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
926 Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >,
927 Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> >
928 > {};
929
930 template <class _Pair>
931 struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair>{};
932
933 template <class _Pair>
934 struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair>{};
935
936 template <class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
937 struct _BothImplicitlyConvertible : false_type{};
938
939 template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
940 struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And<
941 is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>,
942 is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2>
943 > {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944
Louis Dionne9ce598d2021-09-08 09:14:43 -0400945 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500946 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100947 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
948 _BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500949 >::value
950 , int> = 0>
951 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
952 tuple(const pair<_Up1, _Up2>& __p)
Hui Xiea3ac9222022-05-12 13:23:11 +0100953 _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -0500954 : __base_(__p)
955 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000956
Louis Dionne9ce598d2021-09-08 09:14:43 -0400957 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500958 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100959 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
960 _Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500961 >::value
962 , int> = 0>
963 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
964 explicit tuple(const pair<_Up1, _Up2>& __p)
Hui Xiea3ac9222022-05-12 13:23:11 +0100965 _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -0500966 : __base_(__p)
967 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000968
Louis Dionne9ce598d2021-09-08 09:14:43 -0400969 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500970 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100971 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
972 _BothImplicitlyConvertible<const pair<_Up1, _Up2>&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500973 >::value
974 , int> = 0>
975 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
976 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
977 : __base_(allocator_arg_t(), __a, __p)
978 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979
Louis Dionne9ce598d2021-09-08 09:14:43 -0400980 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500981 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +0100982 _EnableCtorFromPair<const pair<_Up1, _Up2>&>,
983 _Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -0500984 >::value
985 , int> = 0>
986 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
987 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
988 : __base_(allocator_arg_t(), __a, __p)
989 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000990
Hui Xiea3ac9222022-05-12 13:23:11 +0100991#if _LIBCPP_STD_VER > 20
992 // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
Eric Fiselierec5a2102019-07-12 23:01:48 +0000993
Hui Xiea3ac9222022-05-12 13:23:11 +0100994 template <class _U1, class _U2, enable_if_t<
995 _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
996 _LIBCPP_HIDE_FROM_ABI constexpr
997 explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
998 tuple(pair<_U1, _U2>& __p) : __base_(__p) {}
999
1000 template <class _Alloc, class _U1, class _U2, enable_if_t<
1001 _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr>
1002 _LIBCPP_HIDE_FROM_ABI constexpr
1003 explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
1004 tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p) : __base_(allocator_arg_t(), __alloc, __p) {}
1005#endif
1006
1007 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001008
Louis Dionne9ce598d2021-09-08 09:14:43 -04001009 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001010 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +01001011 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1012 _BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001013 >::value
1014 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -04001015 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -05001016 tuple(pair<_Up1, _Up2>&& __p)
Hui Xiea3ac9222022-05-12 13:23:11 +01001017 _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -05001018 : __base_(_VSTD::move(__p))
1019 { }
1020
Louis Dionne9ce598d2021-09-08 09:14:43 -04001021 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001022 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +01001023 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1024 _Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001025 >::value
1026 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -04001027 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -05001028 explicit tuple(pair<_Up1, _Up2>&& __p)
Hui Xiea3ac9222022-05-12 13:23:11 +01001029 _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value))
Louis Dionne574e2e32021-02-10 16:19:50 -05001030 : __base_(_VSTD::move(__p))
1031 { }
1032
Louis Dionne9ce598d2021-09-08 09:14:43 -04001033 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001034 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +01001035 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1036 _BothImplicitlyConvertible<pair<_Up1, _Up2>&&> // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001037 >::value
1038 , int> = 0>
1039 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1040 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
1041 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
1042 { }
1043
Louis Dionne9ce598d2021-09-08 09:14:43 -04001044 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -05001045 _And<
Hui Xiea3ac9222022-05-12 13:23:11 +01001046 _EnableCtorFromPair<pair<_Up1, _Up2>&&>,
1047 _Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> > // explicit check
Louis Dionne574e2e32021-02-10 16:19:50 -05001048 >::value
1049 , int> = 0>
1050 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1051 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
1052 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
1053 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +00001054
Hui Xiea3ac9222022-05-12 13:23:11 +01001055#if _LIBCPP_STD_VER > 20
1056 // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
1057
1058 template <class _U1, class _U2, enable_if_t<
1059 _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
1060 _LIBCPP_HIDE_FROM_ABI constexpr
1061 explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
1062 tuple(const pair<_U1, _U2>&& __p) : __base_(std::move(__p)) {}
1063
1064 template <class _Alloc, class _U1, class _U2, enable_if_t<
1065 _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
1066 _LIBCPP_HIDE_FROM_ABI constexpr
1067 explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
1068 tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
1069 : __base_(allocator_arg_t(), __alloc, std::move(__p)) {}
1070#endif // _LIBCPP_STD_VER > 20
1071
Louis Dionne6c0d5342018-07-31 11:56:20 -04001072 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001073 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001074 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
1075 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +00001076 {
Louis Dionne6c0d5342018-07-31 11:56:20 -04001077 _VSTD::__memberwise_copy_assign(*this, __tuple,
1078 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +00001079 return *this;
1080 }
1081
Hui Xiea3ac9222022-05-12 13:23:11 +01001082#if _LIBCPP_STD_VER > 20
1083 _LIBCPP_HIDE_FROM_ABI constexpr
1084 const tuple& operator=(tuple const& __tuple) const
1085 requires (_And<is_copy_assignable<const _Tp>...>::value) {
1086 std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
1087 return *this;
1088 }
1089
1090 _LIBCPP_HIDE_FROM_ABI constexpr
1091 const tuple& operator=(tuple&& __tuple) const
1092 requires (_And<is_assignable<const _Tp&, _Tp>...>::value) {
1093 std::__memberwise_forward_assign(*this,
1094 std::move(__tuple),
1095 __tuple_types<_Tp...>(),
1096 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1097 return *this;
1098 }
1099#endif // _LIBCPP_STD_VER > 20
1100
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001101 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001102 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
1103 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +00001104 {
Louis Dionne6c0d5342018-07-31 11:56:20 -04001105 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1106 __tuple_types<_Tp...>(),
1107 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +00001108 return *this;
1109 }
1110
Louis Dionne9ce598d2021-09-08 09:14:43 -04001111 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001112 _And<
1113 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1114 is_assignable<_Tp&, _Up const&>...
1115 >::value
1116 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001117 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001118 tuple& operator=(tuple<_Up...> const& __tuple)
1119 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1120 {
1121 _VSTD::__memberwise_copy_assign(*this, __tuple,
1122 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1123 return *this;
1124 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001125
Louis Dionne9ce598d2021-09-08 09:14:43 -04001126 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001127 _And<
1128 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
1129 is_assignable<_Tp&, _Up>...
1130 >::value
1131 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001132 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001133 tuple& operator=(tuple<_Up...>&& __tuple)
1134 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1135 {
1136 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
1137 __tuple_types<_Up...>(),
1138 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1139 return *this;
1140 }
1141
Hui Xiea3ac9222022-05-12 13:23:11 +01001142
1143#if _LIBCPP_STD_VER > 20
1144 template <class... _UTypes, enable_if_t<
1145 _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
1146 is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
1147 _LIBCPP_HIDE_FROM_ABI constexpr
1148 const tuple& operator=(const tuple<_UTypes...>& __u) const {
1149 std::__memberwise_copy_assign(*this,
1150 __u,
1151 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1152 return *this;
1153 }
1154
1155 template <class... _UTypes, enable_if_t<
1156 _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
1157 is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr>
1158 _LIBCPP_HIDE_FROM_ABI constexpr
1159 const tuple& operator=(tuple<_UTypes...>&& __u) const {
1160 std::__memberwise_forward_assign(*this,
1161 __u,
1162 __tuple_types<_UTypes...>(),
1163 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1164 return *this;
1165 }
1166#endif // _LIBCPP_STD_VER > 20
1167
1168 template <template<class...> class Pred, bool _Const,
1169 class _Pair, class _DecayedPair = __uncvref_t<_Pair>, class _Tuple = tuple>
1170 struct _AssignPredicateFromPair : false_type {};
1171
1172 template <template<class...> class Pred, bool _Const,
1173 class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2>
1174 struct _AssignPredicateFromPair<Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > :
1175 _And<Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >,
1176 Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> >
1177 > {};
1178
1179 template <bool _Const, class _Pair>
1180 struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {};
1181
1182 template <bool _Const, class _Pair>
1183 struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
1184
1185#if _LIBCPP_STD_VER > 20
1186 template <class _U1, class _U2, enable_if_t<
1187 _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
1188 _LIBCPP_HIDE_FROM_ABI constexpr
1189 const tuple& operator=(const pair<_U1, _U2>& __pair) const
1190 noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
1191 std::get<0>(*this) = __pair.first;
1192 std::get<1>(*this) = __pair.second;
1193 return *this;
1194 }
1195
1196 template <class _U1, class _U2, enable_if_t<
1197 _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr>
1198 _LIBCPP_HIDE_FROM_ABI constexpr
1199 const tuple& operator=(pair<_U1, _U2>&& __pair) const
1200 noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) {
1201 std::get<0>(*this) = std::move(__pair.first);
1202 std::get<1>(*this) = std::move(__pair.second);
1203 return *this;
1204 }
1205#endif // _LIBCPP_STD_VER > 20
1206
1207 template<class _Up1, class _Up2, __enable_if_t<
1208 _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value
Louis Dionne6c0d5342018-07-31 11:56:20 -04001209 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001210 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001211 tuple& operator=(pair<_Up1, _Up2> const& __pair)
Hui Xiea3ac9222022-05-12 13:23:11 +01001212 _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value))
Louis Dionne6c0d5342018-07-31 11:56:20 -04001213 {
1214 _VSTD::get<0>(*this) = __pair.first;
1215 _VSTD::get<1>(*this) = __pair.second;
1216 return *this;
1217 }
1218
Hui Xiea3ac9222022-05-12 13:23:11 +01001219 template<class _Up1, class _Up2, __enable_if_t<
1220 _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value
Louis Dionne6c0d5342018-07-31 11:56:20 -04001221 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001222 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001223 tuple& operator=(pair<_Up1, _Up2>&& __pair)
Hui Xiea3ac9222022-05-12 13:23:11 +01001224 _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value))
Louis Dionne6c0d5342018-07-31 11:56:20 -04001225 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001226 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1227 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001228 return *this;
1229 }
1230
1231 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001232 template<class _Up, size_t _Np, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001233 _And<
1234 _BoolConstant<_Np == sizeof...(_Tp)>,
1235 is_assignable<_Tp&, _Up const&>...
1236 >::value
1237 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001238 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001239 tuple& operator=(array<_Up, _Np> const& __array)
1240 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1241 {
1242 _VSTD::__memberwise_copy_assign(*this, __array,
1243 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1244 return *this;
1245 }
1246
1247 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001248 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001249 _And<
1250 _BoolConstant<_Np == sizeof...(_Tp)>,
1251 is_assignable<_Tp&, _Up>...
1252 >::value
1253 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001254 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001255 tuple& operator=(array<_Up, _Np>&& __array)
1256 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1257 {
1258 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1259 __tuple_types<_If<true, _Up, _Tp>...>(),
1260 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1261 return *this;
1262 }
1263
1264 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001265 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001266 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001267 {__base_.swap(__t.__base_);}
Hui Xiea3ac9222022-05-12 13:23:11 +01001268
1269#if _LIBCPP_STD_VER > 20
1270 _LIBCPP_HIDE_FROM_ABI constexpr
1271 void swap(const tuple& __t) const noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
1272 __base_.swap(__t.__base_);
1273 }
1274#endif // _LIBCPP_STD_VER > 20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275};
1276
1277template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001278class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001279{
1280public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001281 _LIBCPP_INLINE_VISIBILITY constexpr
1282 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001284 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001285 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001288 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001289 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001290 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001291 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001292 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001293 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001294 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001295 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001296 void swap(tuple&) _NOEXCEPT {}
Hui Xiea3ac9222022-05-12 13:23:11 +01001297#if _LIBCPP_STD_VER > 20
1298 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
1299#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001300};
1301
Joe Loserd9b3d972022-03-12 10:46:57 -05001302#if _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001303template <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual>
1304 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
1305struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1306 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1307};
1308
1309template <class... _TTypes, class... _UTypes>
1310 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
1311struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1312 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1313};
Joe Loserd9b3d972022-03-12 10:46:57 -05001314#endif // _LIBCPP_STD_VER > 20
Nikolas Klauserad26ba52022-01-17 19:45:42 +01001315
1316#if _LIBCPP_STD_VER > 14
Louis Dionne616da2a2019-08-12 18:30:31 +00001317template <class ..._Tp>
1318tuple(_Tp...) -> tuple<_Tp...>;
1319template <class _Tp1, class _Tp2>
1320tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1321template <class _Alloc, class ..._Tp>
1322tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1323template <class _Alloc, class _Tp1, class _Tp2>
1324tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1325template <class _Alloc, class ..._Tp>
1326tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001327#endif
1328
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001330inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001331typename enable_if
1332<
1333 __all<__is_swappable<_Tp>::value...>::value,
1334 void
1335>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001336swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1337 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1338 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001339
Hui Xiea3ac9222022-05-12 13:23:11 +01001340#if _LIBCPP_STD_VER > 20
1341template <class... _Tp>
1342_LIBCPP_HIDE_FROM_ABI constexpr
1343enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
1344swap(const tuple<_Tp...>& __lhs, const tuple<_Tp...>& __rhs)
1345 noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
1346 __lhs.swap(__rhs);
1347}
1348#endif
1349
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350// get
1351
1352template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001353inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001354typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001355get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001356{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001357 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001358 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001359}
1360
1361template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001362inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001363const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001364get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001365{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001366 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001367 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368}
1369
Howard Hinnant22e97242010-11-17 19:52:17 +00001370template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001371inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001372typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001373get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001374{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001375 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001376 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001377 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001378}
1379
Eric Fiselier6dea8092015-12-18 00:36:55 +00001380template <size_t _Ip, class ..._Tp>
1381inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1382const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1383get(const tuple<_Tp...>&& __t) _NOEXCEPT
1384{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001385 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001386 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001387 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001388}
1389
Marshall Clow15b02e02013-07-13 02:54:05 +00001390#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001391
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001392namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001393
Louis Dionne7dd28aa2021-07-20 11:46:05 -04001394static constexpr size_t __not_found = static_cast<size_t>(-1);
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001395static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001396
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001397inline _LIBCPP_INLINE_VISIBILITY
1398constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1399 return !__matches ? __res :
1400 (__res == __not_found ? __curr_i : __ambiguous);
1401}
Marshall Clow15b02e02013-07-13 02:54:05 +00001402
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001403template <size_t _Nx>
1404inline _LIBCPP_INLINE_VISIBILITY
1405constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1406 return __i == _Nx ? __not_found :
1407 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1408}
1409
1410template <class _T1, class ..._Args>
1411struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001412 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001413 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001414 static_assert(value != __not_found, "type not found in type list" );
1415 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001416};
1417
Eric Fiselier8087d302016-07-02 03:46:08 +00001418template <class _T1>
1419struct __find_exactly_one_checked<_T1> {
1420 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1421};
1422
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001423} // namespace __find_detail
Marshall Clow15b02e02013-07-13 02:54:05 +00001424
1425template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001426struct __find_exactly_one_t
1427 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1428};
Marshall Clow15b02e02013-07-13 02:54:05 +00001429
1430template <class _T1, class... _Args>
1431inline _LIBCPP_INLINE_VISIBILITY
1432constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1433{
1434 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1435}
1436
1437template <class _T1, class... _Args>
1438inline _LIBCPP_INLINE_VISIBILITY
1439constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1440{
1441 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1442}
1443
1444template <class _T1, class... _Args>
1445inline _LIBCPP_INLINE_VISIBILITY
1446constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1447{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001448 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001449}
1450
Eric Fiselier6dea8092015-12-18 00:36:55 +00001451template <class _T1, class... _Args>
1452inline _LIBCPP_INLINE_VISIBILITY
1453constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1454{
1455 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1456}
1457
Marshall Clow15b02e02013-07-13 02:54:05 +00001458#endif
1459
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460// tie
1461
1462template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001463inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001465tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001466{
1467 return tuple<_Tp&...>(__t...);
1468}
1469
1470template <class _Up>
1471struct __ignore_t
1472{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001473 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001474 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1475 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001476};
1477
Eric Fiselier24e70262017-02-06 01:25:31 +00001478namespace {
Louis Dionne559be102021-09-22 09:35:32 -04001479 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Nikolas Klauserd26407a2021-12-02 14:12:51 +01001480} // namespace
Howard Hinnantc51e1022010-05-11 19:42:16 +00001481
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001483inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001484tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001485make_tuple(_Tp&&... __t)
1486{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001487 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488}
1489
Howard Hinnant3d203a32010-08-19 18:59:38 +00001490template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001491inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1492tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001493forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001494{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001495 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001496}
1497
Howard Hinnantc834c512011-11-29 18:15:50 +00001498template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001499struct __tuple_equal
1500{
1501 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001502 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001503 bool operator()(const _Tp& __x, const _Up& __y)
1504 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001505 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506 }
1507};
1508
1509template <>
1510struct __tuple_equal<0>
1511{
1512 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001513 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514 bool operator()(const _Tp&, const _Up&)
1515 {
1516 return true;
1517 }
1518};
1519
1520template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001521inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001522bool
1523operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1524{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001525 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1527}
1528
Joe Loserd9b3d972022-03-12 10:46:57 -05001529#if _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001530
1531// operator<=>
1532
1533template <class ..._Tp, class ..._Up, size_t ..._Is>
1534_LIBCPP_HIDE_FROM_ABI constexpr
1535auto
1536__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) {
1537 common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal;
1538 static_cast<void>(((__result = _VSTD::__synth_three_way(_VSTD::get<_Is>(__x), _VSTD::get<_Is>(__y)), __result != 0) || ...));
1539 return __result;
1540}
1541
1542template <class ..._Tp, class ..._Up>
1543requires (sizeof...(_Tp) == sizeof...(_Up))
1544_LIBCPP_HIDE_FROM_ABI constexpr
1545common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
1546operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1547{
1548 return _VSTD::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
1549}
1550
Joe Loserd9b3d972022-03-12 10:46:57 -05001551#else // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001552
Howard Hinnantc51e1022010-05-11 19:42:16 +00001553template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001554inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555bool
1556operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1557{
1558 return !(__x == __y);
1559}
1560
Howard Hinnantc834c512011-11-29 18:15:50 +00001561template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562struct __tuple_less
1563{
1564 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001565 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001566 bool operator()(const _Tp& __x, const _Up& __y)
1567 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001568 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1569 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1570 return true;
1571 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1572 return false;
1573 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574 }
1575};
1576
1577template <>
1578struct __tuple_less<0>
1579{
1580 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001581 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582 bool operator()(const _Tp&, const _Up&)
1583 {
1584 return false;
1585 }
1586};
1587
1588template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001589inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590bool
1591operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1592{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001593 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001594 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1595}
1596
1597template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001598inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001599bool
1600operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1601{
1602 return __y < __x;
1603}
1604
1605template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001606inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607bool
1608operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1609{
1610 return !(__x < __y);
1611}
1612
1613template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001614inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001615bool
1616operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1617{
1618 return !(__y < __x);
1619}
1620
Joe Loserd9b3d972022-03-12 10:46:57 -05001621#endif // _LIBCPP_STD_VER > 17
Kent Ross0861b0d2021-10-08 14:54:28 -07001622
Howard Hinnantc51e1022010-05-11 19:42:16 +00001623// tuple_cat
1624
Howard Hinnant6256ee72010-12-11 20:47:50 +00001625template <class _Tp, class _Up> struct __tuple_cat_type;
1626
1627template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001628struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001630 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001631};
1632
1633template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1634struct __tuple_cat_return_1
1635{
1636};
1637
1638template <class ..._Types, class _Tuple0>
1639struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1640{
Nikolas Klauser669b4452022-02-17 22:53:20 +01001641 using type _LIBCPP_NODEBUG = typename __tuple_cat_type<
1642 tuple<_Types...>,
1643 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
1644 >::type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001645};
1646
1647template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1648struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1649 : public __tuple_cat_return_1<
1650 typename __tuple_cat_type<
1651 tuple<_Types...>,
Nikolas Klauser669b4452022-02-17 22:53:20 +01001652 typename __make_tuple_types<__uncvref_t<_Tuple0> >::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001653 >::type,
1654 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1655 _Tuple1, _Tuples...>
1656{
1657};
1658
1659template <class ..._Tuples> struct __tuple_cat_return;
1660
1661template <class _Tuple0, class ..._Tuples>
1662struct __tuple_cat_return<_Tuple0, _Tuples...>
1663 : public __tuple_cat_return_1<tuple<>,
1664 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1665 _Tuples...>
1666{
1667};
1668
1669template <>
1670struct __tuple_cat_return<>
1671{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001672 typedef _LIBCPP_NODEBUG tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001673};
1674
Marshall Clow2229cee2013-07-22 16:02:19 +00001675inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001676tuple<>
1677tuple_cat()
1678{
1679 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001680}
1681
Howard Hinnantc834c512011-11-29 18:15:50 +00001682template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001683struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001684
Howard Hinnant21376f62010-12-12 23:04:37 +00001685template <class ..._Types, size_t ..._I0, class _Tuple0>
1686struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001687{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001688 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001689 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1690 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1691};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001692
Howard Hinnant21376f62010-12-12 23:04:37 +00001693template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1694struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1695 _Tuple0, _Tuple1, _Tuples...>
1696 : public __tuple_cat_return_ref_imp<
1697 tuple<_Types..., typename __apply_cv<_Tuple0,
1698 typename tuple_element<_I0,
1699 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1700 typename __make_tuple_indices<tuple_size<typename
1701 remove_reference<_Tuple1>::type>::value>::type,
1702 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001703{
Howard Hinnant21376f62010-12-12 23:04:37 +00001704};
1705
1706template <class _Tuple0, class ..._Tuples>
1707struct __tuple_cat_return_ref
1708 : public __tuple_cat_return_ref_imp<tuple<>,
1709 typename __make_tuple_indices<
1710 tuple_size<typename remove_reference<_Tuple0>::type>::value
1711 >::type, _Tuple0, _Tuples...>
1712{
1713};
1714
1715template <class _Types, class _I0, class _J0>
1716struct __tuple_cat;
1717
1718template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001719struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001720{
1721 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001722 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001723 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1724 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1725 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001726 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
David Blaikie699a5e22019-10-28 18:03:59 -07001727 return _VSTD::forward_as_tuple(
1728 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1729 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001730 }
1731
1732 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001733 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001734 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1735 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1736 {
Louis Dionne6209e9f2022-03-03 13:39:12 -05001737 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001738 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1739 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001740 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001741 tuple<_Types...,
1742 typename __apply_cv<_Tuple0, typename tuple_element<
1743 _J0, _T0>::type>::type&&...>,
1744 typename __make_tuple_indices<sizeof...(_Types) +
1745 tuple_size<_T0>::value>::type,
1746 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1747 _VSTD::forward_as_tuple(
1748 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1749 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1750 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001751 }
1752};
1753
1754template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001755inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001756typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1757tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1758{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001759 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001760 return __tuple_cat<tuple<>, __tuple_indices<>,
1761 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001762 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1763 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001764}
1765
1766template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001767struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001768 : true_type {};
1769
Howard Hinnantc51e1022010-05-11 19:42:16 +00001770template <class _T1, class _T2>
1771template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001772inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001773pair<_T1, _T2>::pair(piecewise_construct_t,
1774 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1775 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001776 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1777 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001778{
1779}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001780
Eric Fiselier8e892c52016-07-18 00:35:56 +00001781#if _LIBCPP_STD_VER > 14
1782template <class _Tp>
Louis Dionne559be102021-09-22 09:35:32 -04001783inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001784
1785#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1786
1787template <class _Fn, class _Tuple, size_t ..._Id>
1788inline _LIBCPP_INLINE_VISIBILITY
1789constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1790 __tuple_indices<_Id...>)
1791_LIBCPP_NOEXCEPT_RETURN(
Nikolas Klausera28f48e2022-04-06 23:10:21 +02001792 _VSTD::__invoke(
Eric Fiselier8e892c52016-07-18 00:35:56 +00001793 _VSTD::forward<_Fn>(__f),
1794 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1795)
1796
1797template <class _Fn, class _Tuple>
1798inline _LIBCPP_INLINE_VISIBILITY
1799constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1800_LIBCPP_NOEXCEPT_RETURN(
1801 _VSTD::__apply_tuple_impl(
1802 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001803 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001804)
1805
1806template <class _Tp, class _Tuple, size_t... _Idx>
1807inline _LIBCPP_INLINE_VISIBILITY
1808constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1809_LIBCPP_NOEXCEPT_RETURN(
1810 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1811)
1812
1813template <class _Tp, class _Tuple>
1814inline _LIBCPP_INLINE_VISIBILITY
1815constexpr _Tp make_from_tuple(_Tuple&& __t)
1816_LIBCPP_NOEXCEPT_RETURN(
1817 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001818 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001819)
1820
1821#undef _LIBCPP_NOEXCEPT_RETURN
1822
1823#endif // _LIBCPP_STD_VER > 14
1824
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001825#endif // !defined(_LIBCPP_CXX03_LANG)
1826
Howard Hinnantc51e1022010-05-11 19:42:16 +00001827_LIBCPP_END_NAMESPACE_STD
1828
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001829#endif // _LIBCPP_TUPLE