blob: 3a4b0dfec5f00624752006f304b50bb450b288bb [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- tuple ------------------------------------===//
3//
Chandler Carruth7642bb12019-01-19 08:50:56 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TUPLE
11#define _LIBCPP_TUPLE
12
13/*
14 tuple synopsis
15
16namespace std
17{
18
19template <class... T>
20class tuple {
21public:
Louis Dionnea7a2beb2019-09-26 14:51:10 +000022 explicit(see-below) constexpr tuple();
Louis Dionne1afad1d2019-07-22 20:45:23 +000023 explicit(see-below) tuple(const T&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000024 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000025 explicit(see-below) tuple(U&&...); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000026 tuple(const tuple&) = default;
Howard Hinnant89ef1212011-05-27 19:08:18 +000027 tuple(tuple&&) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +000028 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000029 explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000030 template <class... U>
Louis Dionne1afad1d2019-07-22 20:45:23 +000031 explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000033 explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000034 template <class U1, class U2>
Louis Dionne1afad1d2019-07-22 20:45:23 +000035 explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000036
37 // allocator-extended constructors
38 template <class Alloc>
39 tuple(allocator_arg_t, const Alloc& a);
40 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050041 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050043 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000044 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050045 tuple(allocator_arg_t, const Alloc& a, const tuple&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000046 template <class Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050047 tuple(allocator_arg_t, const Alloc& a, tuple&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000048 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050049 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000050 template <class Alloc, class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050051 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000052 template <class Alloc, class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050053 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000054 template <class Alloc, class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050055 explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050057 tuple& operator=(const tuple&); // constexpr in C++20
58 tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000059 template <class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050060 tuple& operator=(const tuple<U...>&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000061 template <class... U>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050062 tuple& operator=(tuple<U...>&&); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000063 template <class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050064 tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000065 template <class U1, class U2>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050066 tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000067
Louis Dionne6c0d5342018-07-31 11:56:20 -040068 template<class U, size_t N>
69 tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION
70 template<class U, size_t N>
71 tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION
72
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -050073 void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000074};
75
Louis Dionne616da2a2019-08-12 18:30:31 +000076template <class ...T>
77tuple(T...) -> tuple<T...>; // since C++17
78template <class T1, class T2>
79tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
80template <class Alloc, class ...T>
81tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
82template <class Alloc, class T1, class T2>
83tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
84template <class Alloc, class ...T>
85tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
86
Marshall Clowf1bf62f2018-01-02 17:17:01 +000087inline constexpr unspecified ignore;
Howard Hinnantc51e1022010-05-11 19:42:16 +000088
Marshall Clow2229cee2013-07-22 16:02:19 +000089template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
Marshall Clowded420b2013-10-05 18:46:37 +000090template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
Marshall Clowa8892812014-02-25 16:11:46 +000091template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
Marshall Clow2229cee2013-07-22 16:02:19 +000092template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
Eric Fiselier8e892c52016-07-18 00:35:56 +000093
94// [tuple.apply], calling a function with a tuple of arguments:
95template <class F, class Tuple>
96 constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
97template <class T, class Tuple>
98 constexpr T make_from_tuple(Tuple&& t); // C++17
99
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100// 20.4.1.4, tuple helper classes:
Marshall Clowce62b4d2019-01-11 21:57:12 +0000101template <class T> struct tuple_size; // undefined
102template <class... T> struct tuple_size<tuple<T...>>;
Eric Fiselier8e892c52016-07-18 00:35:56 +0000103template <class T>
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000104 inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
Louis Dionnee684aa62019-04-01 16:39:34 +0000105template <size_t I, class T> struct tuple_element; // undefined
106template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
Marshall Clow36907512015-11-19 19:45:29 +0000107template <size_t I, class T>
108 using tuple_element_t = typename tuple_element <I, T>::type; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000109
110// 20.4.1.5, element access:
Marshall Clow36907512015-11-19 19:45:29 +0000111template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000112 typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000113 get(tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000114template <size_t I, class... T>
115 const typename tuple_element<I, tuple<T...>>::type&
Marshall Clow0abb1042013-07-17 18:25:36 +0000116 get(const tuple<T...>&) noexcept; // constexpr in C++14
Marshall Clow36907512015-11-19 19:45:29 +0000117template <size_t I, class... T>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000118 typename tuple_element<I, tuple<T...>>::type&&
Marshall Clow0abb1042013-07-17 18:25:36 +0000119 get(tuple<T...>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000120template <size_t I, class... T>
121 const typename tuple_element<I, tuple<T...>>::type&&
122 get(const tuple<T...>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123
Marshall Clow15b02e02013-07-13 02:54:05 +0000124template <class T1, class... T>
125 constexpr T1& get(tuple<T...>&) noexcept; // C++14
126template <class T1, class... T>
Marshall Clow36907512015-11-19 19:45:29 +0000127 constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000128template <class T1, class... T>
129 constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +0000130template <class T1, class... T>
131 constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
Marshall Clow15b02e02013-07-13 02:54:05 +0000132
Howard Hinnantc51e1022010-05-11 19:42:16 +0000133// 20.4.1.6, relational operators:
Marshall Clow2229cee2013-07-22 16:02:19 +0000134template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
135template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
136template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
137template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
138template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
139template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140
141template <class... Types, class Alloc>
142 struct uses_allocator<tuple<Types...>, Alloc>;
143
144template <class... Types>
Howard Hinnant89ef1212011-05-27 19:08:18 +0000145 void
146 swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148} // std
149
150*/
151
152#include <__config>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400153#include <__functional_base>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000154#include <__utility/forward.h>
155#include <__utility/move.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156#include <__tuple>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400157#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000158#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000160#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000161#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000162
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000163#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000165#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166
167_LIBCPP_BEGIN_NAMESPACE_STD
168
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000169#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170
Marshall Clowf50d66f2014-03-03 06:18:11 +0000171
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172// __tuple_leaf
173
Eric Fiselierf7394302015-06-13 07:08:02 +0000174template <size_t _Ip, class _Hp,
175 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000176 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177class __tuple_leaf;
178
179template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500180inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000182 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000183{
184 swap(__x.get(), __y.get());
185}
186
187template <size_t _Ip, class _Hp, bool>
188class __tuple_leaf
189{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000190 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000191
Eric Fiselierca8bba12016-07-20 02:57:39 +0000192 template <class _Tp>
193 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000194#if __has_keyword(__reference_binds_to_temporary)
195 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000196#else
197 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000198#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000199 }
200
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500201 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202 __tuple_leaf& operator=(const __tuple_leaf&);
203public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500204 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000205 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206 {static_assert(!is_reference<_Hp>::value,
207 "Attempted to default construct a reference element in a tuple");}
208
209 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500210 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000211 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000212 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213 {static_assert(!is_reference<_Hp>::value,
214 "Attempted to default construct a reference element in a tuple");}
215
216 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500217 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000219 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000220 {static_assert(!is_reference<_Hp>::value,
221 "Attempted to default construct a reference element in a tuple");}
222
223 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500224 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000225 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000226 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000227 {static_assert(!is_reference<_Hp>::value,
228 "Attempted to default construct a reference element in a tuple");}
229
Howard Hinnant693fc212010-09-27 17:54:17 +0000230 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000231 class = _EnableIf<
232 _And<
233 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
234 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000235 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000236 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000237 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000238 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000239 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000240 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000241 {static_assert(__can_bind_reference<_Tp&&>(),
242 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243
244 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500245 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000247 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000248 {static_assert(__can_bind_reference<_Tp&&>(),
249 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250
251 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500252 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000254 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000255 {static_assert(!is_reference<_Hp>::value,
256 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257
258 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500259 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000261 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000262 {static_assert(!is_reference<_Hp>::value,
263 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264
Marshall Clow47fcee52014-04-21 23:48:09 +0000265 __tuple_leaf(const __tuple_leaf& __t) = default;
266 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000267
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500268 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000269 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000271 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272 return 0;
273 }
274
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000275 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
276 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000277};
278
279template <size_t _Ip, class _Hp>
280class __tuple_leaf<_Ip, _Hp, true>
281 : private _Hp
282{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500283 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284 __tuple_leaf& operator=(const __tuple_leaf&);
285public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500286 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000287 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288
289 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500290 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
292
293 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500294 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
296 : _Hp(allocator_arg_t(), __a) {}
297
298 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500299 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
301 : _Hp(__a) {}
302
Howard Hinnant693fc212010-09-27 17:54:17 +0000303 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000304 class = _EnableIf<
305 _And<
306 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
307 is_constructible<_Hp, _Tp>
308 >::value
309 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000310 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000311 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000312 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000313 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314
315 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500316 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000318 : _Hp(_VSTD::forward<_Tp>(__t)) {}
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 constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000322 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000323 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324
325 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500326 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000328 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000330 __tuple_leaf(__tuple_leaf const &) = default;
331 __tuple_leaf(__tuple_leaf &&) = default;
332
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500333 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000334 int
335 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000337 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338 return 0;
339 }
340
Marshall Clow2229cee2013-07-22 16:02:19 +0000341 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
342 _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 +0000343};
344
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000345template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500346_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000347void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348
Marshall Clowc470eae2014-10-15 10:33:02 +0000349template <class _Tp>
350struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000351
Marshall Clowc470eae2014-10-15 10:33:02 +0000352template <class ..._Tp>
353struct __all_default_constructible<__tuple_types<_Tp...>>
354 : __all<is_default_constructible<_Tp>::value...>
355{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000356
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357// __tuple_impl
358
359template<class _Indx, class ..._Tp> struct __tuple_impl;
360
361template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000362struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363 : public __tuple_leaf<_Indx, _Tp>...
364{
Howard Hinnant38469632012-07-06 20:39:45 +0000365 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500366 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000367 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000368
Howard Hinnantc51e1022010-05-11 19:42:16 +0000369 template <size_t ..._Uf, class ..._Tf,
370 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000371 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372 explicit
373 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
374 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000375 _Up&&... __u)
376 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
377 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000378 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379 __tuple_leaf<_Ul, _Tl>()...
380 {}
381
382 template <class _Alloc, size_t ..._Uf, class ..._Tf,
383 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500384 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385 explicit
386 __tuple_impl(allocator_arg_t, const _Alloc& __a,
387 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
388 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
389 _Up&&... __u) :
390 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000391 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
393 {}
394
395 template <class _Tuple,
396 class = typename enable_if
397 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000398 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399 >::type
400 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000401 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000402 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
403 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000404 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
405 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000406 {}
407
408 template <class _Alloc, class _Tuple,
409 class = typename enable_if
410 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000411 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412 >::type
413 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500414 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000415 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
416 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000417 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000418 _VSTD::forward<typename tuple_element<_Indx,
419 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420 {}
421
Howard Hinnant0d032d12013-11-06 17:45:43 +0000422 __tuple_impl(const __tuple_impl&) = default;
423 __tuple_impl(__tuple_impl&&) = default;
424
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500425 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000427 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400429 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430 }
431};
432
Louis Dionne6c0d5342018-07-31 11:56:20 -0400433template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500434_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400435void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
436 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
437}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000438
Louis Dionne6c0d5342018-07-31 11:56:20 -0400439template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500440_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400441void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
442 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500443 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400444 ), void(), 0)...);
445}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000446
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000448class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000450 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000452 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000453
Marshall Clow0abb1042013-07-17 18:25:36 +0000454 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000455 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000456 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000457 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000458 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000459 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000460 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
461 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000462public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500463 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464
Louis Dionne574e2e32021-02-10 16:19:50 -0500465 // tuple() constructors (including allocator_arg_t variants)
466 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, _EnableIf<
467 _And<
468 _IsImpDefault<_Tp>... // explicit check
469 >::value
470 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400471 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000472 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500473 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
474 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000475
Louis Dionne574e2e32021-02-10 16:19:50 -0500476 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
477 template<class...> class _IsDefault = is_default_constructible, _EnableIf<
478 _And<
479 _IsDefault<_Tp>...,
480 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
481 >::value
482 , int> = 0>
483 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
484 explicit tuple()
485 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
486 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000487
Louis Dionne574e2e32021-02-10 16:19:50 -0500488 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, _EnableIf<
489 _And<
490 _IsImpDefault<_Tp>... // explicit check
491 >::value
492 , int> = 0>
493 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
494 tuple(allocator_arg_t, _Alloc const& __a)
495 : __base_(allocator_arg_t(), __a,
496 __tuple_indices<>(), __tuple_types<>(),
497 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
498 __tuple_types<_Tp...>()) {}
499
500 template <class _Alloc,
501 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
502 template<class...> class _IsDefault = is_default_constructible, _EnableIf<
503 _And<
504 _IsDefault<_Tp>...,
505 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
506 >::value
507 , int> = 0>
508 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
509 explicit tuple(allocator_arg_t, _Alloc const& __a)
510 : __base_(allocator_arg_t(), __a,
511 __tuple_indices<>(), __tuple_types<>(),
512 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
513 __tuple_types<_Tp...>()) {}
514
515 // tuple(const T&...) constructors (including allocator_arg_t variants)
516 template <template<class...> class _And = _And, _EnableIf<
517 _And<
518 _BoolConstant<sizeof...(_Tp) >= 1>,
519 is_copy_constructible<_Tp>...,
520 is_convertible<const _Tp&, _Tp>... // explicit check
521 >::value
522 , int> = 0>
523 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
524 tuple(const _Tp& ... __t)
525 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
526 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
527 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
528 typename __make_tuple_indices<0>::type(),
529 typename __make_tuple_types<tuple, 0>::type(),
530 __t...
531 ) {}
532
533 template <template<class...> class _And = _And, _EnableIf<
534 _And<
535 _BoolConstant<sizeof...(_Tp) >= 1>,
536 is_copy_constructible<_Tp>...,
537 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
538 >::value
539 , int> = 0>
540 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
541 explicit tuple(const _Tp& ... __t)
542 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
543 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
544 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
545 typename __make_tuple_indices<0>::type(),
546 typename __make_tuple_types<tuple, 0>::type(),
547 __t...
548 ) {}
549
550 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
551 _And<
552 _BoolConstant<sizeof...(_Tp) >= 1>,
553 is_copy_constructible<_Tp>...,
554 is_convertible<const _Tp&, _Tp>... // explicit check
555 >::value
556 , int> = 0>
557 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
558 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
559 : __base_(allocator_arg_t(), __a,
560 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
561 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
562 typename __make_tuple_indices<0>::type(),
563 typename __make_tuple_types<tuple, 0>::type(),
564 __t...
565 ) {}
566
567 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
568 _And<
569 _BoolConstant<sizeof...(_Tp) >= 1>,
570 is_copy_constructible<_Tp>...,
571 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
572 >::value
573 , int> = 0>
574 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
575 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
576 : __base_(allocator_arg_t(), __a,
577 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
578 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
579 typename __make_tuple_indices<0>::type(),
580 typename __make_tuple_types<tuple, 0>::type(),
581 __t...
582 ) {}
583
584 // tuple(U&& ...) constructors (including allocator_arg_t variants)
585 template <class ..._Up> struct _IsThisTuple : false_type { };
586 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
587
588 template <class ..._Up>
589 struct _EnableUTypesCtor : _And<
590 _BoolConstant<sizeof...(_Tp) >= 1>,
591 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
592 is_constructible<_Tp, _Up>...
593 > { };
594
595 template <class ..._Up, _EnableIf<
596 _And<
597 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
598 _EnableUTypesCtor<_Up...>,
599 is_convertible<_Up, _Tp>... // explicit check
600 >::value
601 , int> = 0>
602 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
603 tuple(_Up&&... __u)
604 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
605 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
606 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
607 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
608 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
609 _VSTD::forward<_Up>(__u)...) {}
610
611 template <class ..._Up, _EnableIf<
612 _And<
613 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
614 _EnableUTypesCtor<_Up...>,
615 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
616 >::value
617 , int> = 0>
618 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
619 explicit tuple(_Up&&... __u)
620 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
621 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
622 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
623 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
624 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
625 _VSTD::forward<_Up>(__u)...) {}
626
627 template <class _Alloc, class ..._Up, _EnableIf<
628 _And<
629 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
630 _EnableUTypesCtor<_Up...>,
631 is_convertible<_Up, _Tp>... // explicit check
632 >::value
633 , int> = 0>
634 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
635 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
636 : __base_(allocator_arg_t(), __a,
637 typename __make_tuple_indices<sizeof...(_Up)>::type(),
638 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
639 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
640 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
641 _VSTD::forward<_Up>(__u)...) {}
642
643 template <class _Alloc, class ..._Up, _EnableIf<
644 _And<
645 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
646 _EnableUTypesCtor<_Up...>,
647 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
648 >::value
649 , int> = 0>
650 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
651 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
652 : __base_(allocator_arg_t(), __a,
653 typename __make_tuple_indices<sizeof...(_Up)>::type(),
654 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
655 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
656 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
657 _VSTD::forward<_Up>(__u)...) {}
658
659 // Copy and move constructors (including the allocator_arg_t variants)
660 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000661 tuple(tuple&&) = default;
662
Louis Dionne574e2e32021-02-10 16:19:50 -0500663 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
664 _And<is_copy_constructible<_Tp>...>::value
665 , int> = 0>
666 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
667 : __base_(allocator_arg_t(), __alloc, __t)
668 { }
669
670 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
671 _And<is_move_constructible<_Tp>...>::value
672 , int> = 0>
673 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
674 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
675 { }
676
677 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
678 template <class ..._Up>
679 struct _EnableCopyFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400680 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
681 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500682 _BoolConstant<sizeof...(_Tp) != 1>,
683 // _Tp and _Up are 1-element packs - the pack expansions look
684 // weird to avoid tripping up the type traits in degenerate cases
685 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500686 _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
687 _Not<is_constructible<_Tp, const tuple<_Up>&> >...
688 >
689 >,
690 is_constructible<_Tp, const _Up&>...
691 > { };
692
693 template <class ..._Up, _EnableIf<
694 _And<
695 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
696 _EnableCopyFromOtherTuple<_Up...>,
697 is_convertible<const _Up&, _Tp>... // explicit check
698 >::value
699 , int> = 0>
700 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
701 tuple(const tuple<_Up...>& __t)
702 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
703 : __base_(__t)
704 { }
705
706 template <class ..._Up, _EnableIf<
707 _And<
708 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
709 _EnableCopyFromOtherTuple<_Up...>,
710 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
711 >::value
712 , int> = 0>
713 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
714 explicit tuple(const tuple<_Up...>& __t)
715 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
716 : __base_(__t)
717 { }
718
719 template <class ..._Up, class _Alloc, _EnableIf<
720 _And<
721 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
722 _EnableCopyFromOtherTuple<_Up...>,
723 is_convertible<const _Up&, _Tp>... // explicit check
724 >::value
725 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500726 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500727 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
728 : __base_(allocator_arg_t(), __a, __t)
729 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000730
Louis Dionne574e2e32021-02-10 16:19:50 -0500731 template <class ..._Up, class _Alloc, _EnableIf<
732 _And<
733 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
734 _EnableCopyFromOtherTuple<_Up...>,
735 _Not<_Lazy<_And, is_convertible<const _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, const tuple<_Up...>& __t)
740 : __base_(allocator_arg_t(), __a, __t)
741 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000742
Louis Dionne574e2e32021-02-10 16:19:50 -0500743 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
744 template <class ..._Up>
745 struct _EnableMoveFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400746 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
747 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500748 _BoolConstant<sizeof...(_Tp) != 1>,
749 // _Tp and _Up are 1-element packs - the pack expansions look
750 // weird to avoid tripping up the type traits in degenerate cases
751 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500752 _Not<is_convertible<tuple<_Up>, _Tp> >...,
753 _Not<is_constructible<_Tp, tuple<_Up> > >...
754 >
755 >,
756 is_constructible<_Tp, _Up>...
757 > { };
758
759 template <class ..._Up, _EnableIf<
760 _And<
761 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
762 _EnableMoveFromOtherTuple<_Up...>,
763 is_convertible<_Up, _Tp>... // explicit check
764 >::value
765 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000766 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500767 tuple(tuple<_Up...>&& __t)
768 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
769 : __base_(_VSTD::move(__t))
770 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771
Louis Dionne574e2e32021-02-10 16:19:50 -0500772 template <class ..._Up, _EnableIf<
773 _And<
774 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
775 _EnableMoveFromOtherTuple<_Up...>,
776 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
777 >::value
778 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000779 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500780 explicit tuple(tuple<_Up...>&& __t)
781 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
782 : __base_(_VSTD::move(__t))
783 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000784
Louis Dionne574e2e32021-02-10 16:19:50 -0500785 template <class _Alloc, class ..._Up, _EnableIf<
786 _And<
787 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
788 _EnableMoveFromOtherTuple<_Up...>,
789 is_convertible<_Up, _Tp>... // explicit check
790 >::value
791 , int> = 0>
792 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
793 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
794 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
795 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796
Louis Dionne574e2e32021-02-10 16:19:50 -0500797 template <class _Alloc, class ..._Up, _EnableIf<
798 _And<
799 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
800 _EnableMoveFromOtherTuple<_Up...>,
801 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
802 >::value
803 , int> = 0>
804 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
805 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
806 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
807 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000808
Louis Dionne574e2e32021-02-10 16:19:50 -0500809 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
810 template <class _Up1, class _Up2, class ..._DependentTp>
811 struct _EnableImplicitCopyFromPair : _And<
812 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
813 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
814 is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
815 is_convertible<const _Up2&, _SecondType<_DependentTp...> >
816 > { };
Howard Hinnant65704d02012-04-01 23:10:42 +0000817
Louis Dionne574e2e32021-02-10 16:19:50 -0500818 template <class _Up1, class _Up2, class ..._DependentTp>
819 struct _EnableExplicitCopyFromPair : _And<
820 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
821 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
822 _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
823 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
824 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825
Louis Dionne574e2e32021-02-10 16:19:50 -0500826 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
827 _And<
828 _BoolConstant<sizeof...(_Tp) == 2>,
829 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
830 >::value
831 , int> = 0>
832 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
833 tuple(const pair<_Up1, _Up2>& __p)
834 _NOEXCEPT_((_And<
835 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
836 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
837 >::value))
838 : __base_(__p)
839 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840
Louis Dionne574e2e32021-02-10 16:19:50 -0500841 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
842 _And<
843 _BoolConstant<sizeof...(_Tp) == 2>,
844 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
845 >::value
846 , int> = 0>
847 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
848 explicit tuple(const pair<_Up1, _Up2>& __p)
849 _NOEXCEPT_((_And<
850 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
851 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
852 >::value))
853 : __base_(__p)
854 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000855
Louis Dionne574e2e32021-02-10 16:19:50 -0500856 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
857 _And<
858 _BoolConstant<sizeof...(_Tp) == 2>,
859 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
860 >::value
861 , int> = 0>
862 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
863 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
864 : __base_(allocator_arg_t(), __a, __p)
865 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866
Louis Dionne574e2e32021-02-10 16:19:50 -0500867 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
868 _And<
869 _BoolConstant<sizeof...(_Tp) == 2>,
870 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
871 >::value
872 , int> = 0>
873 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
874 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
875 : __base_(allocator_arg_t(), __a, __p)
876 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000877
Louis Dionne574e2e32021-02-10 16:19:50 -0500878 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
879 template <class _Up1, class _Up2, class ..._DependentTp>
880 struct _EnableImplicitMoveFromPair : _And<
881 is_constructible<_FirstType<_DependentTp...>, _Up1>,
882 is_constructible<_SecondType<_DependentTp...>, _Up2>,
883 is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
884 is_convertible<_Up2, _SecondType<_DependentTp...> >
885 > { };
Eric Fiselierec5a2102019-07-12 23:01:48 +0000886
Louis Dionne574e2e32021-02-10 16:19:50 -0500887 template <class _Up1, class _Up2, class ..._DependentTp>
888 struct _EnableExplicitMoveFromPair : _And<
889 is_constructible<_FirstType<_DependentTp...>, _Up1>,
890 is_constructible<_SecondType<_DependentTp...>, _Up2>,
891 _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
892 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
893 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894
Louis Dionne574e2e32021-02-10 16:19:50 -0500895 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
896 _And<
897 _BoolConstant<sizeof...(_Tp) == 2>,
898 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
899 >::value
900 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400901 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500902 tuple(pair<_Up1, _Up2>&& __p)
903 _NOEXCEPT_((_And<
904 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
905 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
906 >::value))
907 : __base_(_VSTD::move(__p))
908 { }
909
910 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
911 _And<
912 _BoolConstant<sizeof...(_Tp) == 2>,
913 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
914 >::value
915 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400916 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500917 explicit tuple(pair<_Up1, _Up2>&& __p)
918 _NOEXCEPT_((_And<
919 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
920 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
921 >::value))
922 : __base_(_VSTD::move(__p))
923 { }
924
925 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
926 _And<
927 _BoolConstant<sizeof...(_Tp) == 2>,
928 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
929 >::value
930 , int> = 0>
931 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
932 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
933 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
934 { }
935
936 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
937 _And<
938 _BoolConstant<sizeof...(_Tp) == 2>,
939 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
940 >::value
941 , int> = 0>
942 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
943 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
944 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
945 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000946
Louis Dionne6c0d5342018-07-31 11:56:20 -0400947 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500948 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400949 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
950 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000951 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400952 _VSTD::__memberwise_copy_assign(*this, __tuple,
953 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000954 return *this;
955 }
956
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500957 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400958 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
959 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000960 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400961 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
962 __tuple_types<_Tp...>(),
963 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000964 return *this;
965 }
966
Louis Dionne6c0d5342018-07-31 11:56:20 -0400967 template<class... _Up, _EnableIf<
968 _And<
969 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
970 is_assignable<_Tp&, _Up const&>...
971 >::value
972 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500973 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400974 tuple& operator=(tuple<_Up...> const& __tuple)
975 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
976 {
977 _VSTD::__memberwise_copy_assign(*this, __tuple,
978 typename __make_tuple_indices<sizeof...(_Tp)>::type());
979 return *this;
980 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981
Louis Dionne6c0d5342018-07-31 11:56:20 -0400982 template<class... _Up, _EnableIf<
983 _And<
984 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
985 is_assignable<_Tp&, _Up>...
986 >::value
987 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500988 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400989 tuple& operator=(tuple<_Up...>&& __tuple)
990 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
991 {
992 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
993 __tuple_types<_Up...>(),
994 typename __make_tuple_indices<sizeof...(_Tp)>::type());
995 return *this;
996 }
997
998 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
999 _And<_Dep,
1000 _BoolConstant<sizeof...(_Tp) == 2>,
1001 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1002 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1003 >::value
1004 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001005 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001006 tuple& operator=(pair<_Up1, _Up2> const& __pair)
1007 _NOEXCEPT_((_And<
1008 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1009 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1010 >::value))
1011 {
1012 _VSTD::get<0>(*this) = __pair.first;
1013 _VSTD::get<1>(*this) = __pair.second;
1014 return *this;
1015 }
1016
1017 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
1018 _And<_Dep,
1019 _BoolConstant<sizeof...(_Tp) == 2>,
1020 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1021 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1022 >::value
1023 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001024 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001025 tuple& operator=(pair<_Up1, _Up2>&& __pair)
1026 _NOEXCEPT_((_And<
1027 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1028 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1029 >::value))
1030 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001031 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1032 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001033 return *this;
1034 }
1035
1036 // EXTENSION
1037 template<class _Up, size_t _Np, class = _EnableIf<
1038 _And<
1039 _BoolConstant<_Np == sizeof...(_Tp)>,
1040 is_assignable<_Tp&, _Up const&>...
1041 >::value
1042 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001043 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001044 tuple& operator=(array<_Up, _Np> const& __array)
1045 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1046 {
1047 _VSTD::__memberwise_copy_assign(*this, __array,
1048 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1049 return *this;
1050 }
1051
1052 // EXTENSION
1053 template<class _Up, size_t _Np, class = void, class = _EnableIf<
1054 _And<
1055 _BoolConstant<_Np == sizeof...(_Tp)>,
1056 is_assignable<_Tp&, _Up>...
1057 >::value
1058 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001059 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001060 tuple& operator=(array<_Up, _Np>&& __array)
1061 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1062 {
1063 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1064 __tuple_types<_If<true, _Up, _Tp>...>(),
1065 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1066 return *this;
1067 }
1068
1069 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001070 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001071 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001072 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073};
1074
1075template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001076class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077{
1078public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001079 _LIBCPP_INLINE_VISIBILITY constexpr
1080 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001082 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001083 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001085 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001086 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001087 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001088 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001089 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001090 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001091 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001092 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001093 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001094 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001095};
1096
Eric Fiselier8df4ac62017-10-04 00:04:26 +00001097#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Louis Dionne616da2a2019-08-12 18:30:31 +00001098template <class ..._Tp>
1099tuple(_Tp...) -> tuple<_Tp...>;
1100template <class _Tp1, class _Tp2>
1101tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1102template <class _Alloc, class ..._Tp>
1103tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1104template <class _Alloc, class _Tp1, class _Tp2>
1105tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1106template <class _Alloc, class ..._Tp>
1107tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001108#endif
1109
Howard Hinnantc51e1022010-05-11 19:42:16 +00001110template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001111inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001112typename enable_if
1113<
1114 __all<__is_swappable<_Tp>::value...>::value,
1115 void
1116>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001117swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1118 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1119 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001120
1121// get
1122
1123template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001124inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001125typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001126get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001127{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001128 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001129 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130}
1131
1132template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001133inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001134const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001135get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001137 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001138 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001139}
1140
Howard Hinnant22e97242010-11-17 19:52:17 +00001141template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001142inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001143typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001144get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001145{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001146 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001147 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001148 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001149}
1150
Eric Fiselier6dea8092015-12-18 00:36:55 +00001151template <size_t _Ip, class ..._Tp>
1152inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1153const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1154get(const tuple<_Tp...>&& __t) _NOEXCEPT
1155{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001156 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001157 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001158 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001159}
1160
Marshall Clow15b02e02013-07-13 02:54:05 +00001161#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001162
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001163namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001164
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001165static constexpr size_t __not_found = -1;
1166static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001167
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001168inline _LIBCPP_INLINE_VISIBILITY
1169constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1170 return !__matches ? __res :
1171 (__res == __not_found ? __curr_i : __ambiguous);
1172}
Marshall Clow15b02e02013-07-13 02:54:05 +00001173
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001174template <size_t _Nx>
1175inline _LIBCPP_INLINE_VISIBILITY
1176constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1177 return __i == _Nx ? __not_found :
1178 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1179}
1180
1181template <class _T1, class ..._Args>
1182struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001183 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001184 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001185 static_assert(value != __not_found, "type not found in type list" );
1186 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001187};
1188
Eric Fiselier8087d302016-07-02 03:46:08 +00001189template <class _T1>
1190struct __find_exactly_one_checked<_T1> {
1191 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1192};
1193
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001194} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001195
1196template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001197struct __find_exactly_one_t
1198 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1199};
Marshall Clow15b02e02013-07-13 02:54:05 +00001200
1201template <class _T1, class... _Args>
1202inline _LIBCPP_INLINE_VISIBILITY
1203constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1204{
1205 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1206}
1207
1208template <class _T1, class... _Args>
1209inline _LIBCPP_INLINE_VISIBILITY
1210constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1211{
1212 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1213}
1214
1215template <class _T1, class... _Args>
1216inline _LIBCPP_INLINE_VISIBILITY
1217constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1218{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001219 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001220}
1221
Eric Fiselier6dea8092015-12-18 00:36:55 +00001222template <class _T1, class... _Args>
1223inline _LIBCPP_INLINE_VISIBILITY
1224constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1225{
1226 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1227}
1228
Marshall Clow15b02e02013-07-13 02:54:05 +00001229#endif
1230
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231// tie
1232
1233template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001234inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001235tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001236tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001237{
1238 return tuple<_Tp&...>(__t...);
1239}
1240
1241template <class _Up>
1242struct __ignore_t
1243{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001245 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1246 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001247};
1248
Eric Fiselier24e70262017-02-06 01:25:31 +00001249namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001250 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001251}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001252
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001254inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001255tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001256make_tuple(_Tp&&... __t)
1257{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001258 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001259}
1260
Howard Hinnant3d203a32010-08-19 18:59:38 +00001261template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001262inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1263tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001264forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001265{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001266 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001267}
1268
Howard Hinnantc834c512011-11-29 18:15:50 +00001269template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270struct __tuple_equal
1271{
1272 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001273 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001274 bool operator()(const _Tp& __x, const _Up& __y)
1275 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001276 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277 }
1278};
1279
1280template <>
1281struct __tuple_equal<0>
1282{
1283 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001284 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285 bool operator()(const _Tp&, const _Up&)
1286 {
1287 return true;
1288 }
1289};
1290
1291template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001292inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293bool
1294operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1295{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001296 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1298}
1299
1300template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001301inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001302bool
1303operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1304{
1305 return !(__x == __y);
1306}
1307
Howard Hinnantc834c512011-11-29 18:15:50 +00001308template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001309struct __tuple_less
1310{
1311 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001312 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313 bool operator()(const _Tp& __x, const _Up& __y)
1314 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001315 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1316 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1317 return true;
1318 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1319 return false;
1320 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321 }
1322};
1323
1324template <>
1325struct __tuple_less<0>
1326{
1327 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001328 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329 bool operator()(const _Tp&, const _Up&)
1330 {
1331 return false;
1332 }
1333};
1334
1335template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001336inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337bool
1338operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1339{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001340 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001341 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1342}
1343
1344template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001345inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346bool
1347operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1348{
1349 return __y < __x;
1350}
1351
1352template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001353inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001354bool
1355operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1356{
1357 return !(__x < __y);
1358}
1359
1360template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001361inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001362bool
1363operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1364{
1365 return !(__y < __x);
1366}
1367
1368// tuple_cat
1369
Howard Hinnant6256ee72010-12-11 20:47:50 +00001370template <class _Tp, class _Up> struct __tuple_cat_type;
1371
1372template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001373struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001374{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001375 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001376};
1377
1378template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1379struct __tuple_cat_return_1
1380{
1381};
1382
1383template <class ..._Types, class _Tuple0>
1384struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1385{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001386 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001387 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001388 type;
1389};
1390
1391template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1392struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1393 : public __tuple_cat_return_1<
1394 typename __tuple_cat_type<
1395 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001396 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001397 >::type,
1398 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1399 _Tuple1, _Tuples...>
1400{
1401};
1402
1403template <class ..._Tuples> struct __tuple_cat_return;
1404
1405template <class _Tuple0, class ..._Tuples>
1406struct __tuple_cat_return<_Tuple0, _Tuples...>
1407 : public __tuple_cat_return_1<tuple<>,
1408 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1409 _Tuples...>
1410{
1411};
1412
1413template <>
1414struct __tuple_cat_return<>
1415{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001416 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001417};
1418
Marshall Clow2229cee2013-07-22 16:02:19 +00001419inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001420tuple<>
1421tuple_cat()
1422{
1423 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424}
1425
Howard Hinnantc834c512011-11-29 18:15:50 +00001426template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001427struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428
Howard Hinnant21376f62010-12-12 23:04:37 +00001429template <class ..._Types, size_t ..._I0, class _Tuple0>
1430struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001432 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001433 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1434 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1435};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001436
Howard Hinnant21376f62010-12-12 23:04:37 +00001437template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1438struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1439 _Tuple0, _Tuple1, _Tuples...>
1440 : public __tuple_cat_return_ref_imp<
1441 tuple<_Types..., typename __apply_cv<_Tuple0,
1442 typename tuple_element<_I0,
1443 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1444 typename __make_tuple_indices<tuple_size<typename
1445 remove_reference<_Tuple1>::type>::value>::type,
1446 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447{
Howard Hinnant21376f62010-12-12 23:04:37 +00001448};
1449
1450template <class _Tuple0, class ..._Tuples>
1451struct __tuple_cat_return_ref
1452 : public __tuple_cat_return_ref_imp<tuple<>,
1453 typename __make_tuple_indices<
1454 tuple_size<typename remove_reference<_Tuple0>::type>::value
1455 >::type, _Tuple0, _Tuples...>
1456{
1457};
1458
1459template <class _Types, class _I0, class _J0>
1460struct __tuple_cat;
1461
1462template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001463struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001464{
1465 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001466 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001467 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1468 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1469 {
David Blaikie699a5e22019-10-28 18:03:59 -07001470 return _VSTD::forward_as_tuple(
1471 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1472 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001473 }
1474
1475 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001476 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001477 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1478 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1479 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001480 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1481 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001482 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001483 tuple<_Types...,
1484 typename __apply_cv<_Tuple0, typename tuple_element<
1485 _J0, _T0>::type>::type&&...>,
1486 typename __make_tuple_indices<sizeof...(_Types) +
1487 tuple_size<_T0>::value>::type,
1488 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1489 _VSTD::forward_as_tuple(
1490 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1491 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1492 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001493 }
1494};
1495
1496template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001497inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001498typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1499tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1500{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001501 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001502 return __tuple_cat<tuple<>, __tuple_indices<>,
1503 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001504 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1505 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506}
1507
1508template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001509struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001510 : true_type {};
1511
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512template <class _T1, class _T2>
1513template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001514inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001515pair<_T1, _T2>::pair(piecewise_construct_t,
1516 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1517 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001518 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1519 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520{
1521}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001522
Eric Fiselier8e892c52016-07-18 00:35:56 +00001523#if _LIBCPP_STD_VER > 14
1524template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001525_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001526
1527#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1528
1529template <class _Fn, class _Tuple, size_t ..._Id>
1530inline _LIBCPP_INLINE_VISIBILITY
1531constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1532 __tuple_indices<_Id...>)
1533_LIBCPP_NOEXCEPT_RETURN(
1534 _VSTD::__invoke_constexpr(
1535 _VSTD::forward<_Fn>(__f),
1536 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1537)
1538
1539template <class _Fn, class _Tuple>
1540inline _LIBCPP_INLINE_VISIBILITY
1541constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1542_LIBCPP_NOEXCEPT_RETURN(
1543 _VSTD::__apply_tuple_impl(
1544 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001545 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001546)
1547
1548template <class _Tp, class _Tuple, size_t... _Idx>
1549inline _LIBCPP_INLINE_VISIBILITY
1550constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1551_LIBCPP_NOEXCEPT_RETURN(
1552 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1553)
1554
1555template <class _Tp, class _Tuple>
1556inline _LIBCPP_INLINE_VISIBILITY
1557constexpr _Tp make_from_tuple(_Tuple&& __t)
1558_LIBCPP_NOEXCEPT_RETURN(
1559 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001560 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001561)
1562
1563#undef _LIBCPP_NOEXCEPT_RETURN
1564
1565#endif // _LIBCPP_STD_VER > 14
1566
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001567#endif // !defined(_LIBCPP_CXX03_LANG)
1568
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569_LIBCPP_END_NAMESPACE_STD
1570
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001571#endif // _LIBCPP_TUPLE