blob: 42e05b988faa8be631fc0d4a2f248723fc3fe866 [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 Bella599a6c62021-06-09 23:10:17 +0000154#include <__functional/unwrap_ref.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000155#include <__utility/forward.h>
156#include <__utility/move.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000157#include <__tuple>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400158#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000161#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000162#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000164#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000166#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167
168_LIBCPP_BEGIN_NAMESPACE_STD
169
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000170#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000171
Marshall Clowf50d66f2014-03-03 06:18:11 +0000172
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173// __tuple_leaf
174
Eric Fiselierf7394302015-06-13 07:08:02 +0000175template <size_t _Ip, class _Hp,
176 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000177 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178class __tuple_leaf;
179
180template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500181inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000183 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184{
185 swap(__x.get(), __y.get());
186}
187
188template <size_t _Ip, class _Hp, bool>
189class __tuple_leaf
190{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000191 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192
Eric Fiselierca8bba12016-07-20 02:57:39 +0000193 template <class _Tp>
194 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000195#if __has_keyword(__reference_binds_to_temporary)
196 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000197#else
198 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000199#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000200 }
201
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500202 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203 __tuple_leaf& operator=(const __tuple_leaf&);
204public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500205 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000206 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207 {static_assert(!is_reference<_Hp>::value,
208 "Attempted to default construct a reference element in a tuple");}
209
210 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500211 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000213 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000214 {static_assert(!is_reference<_Hp>::value,
215 "Attempted to default construct a reference element in a tuple");}
216
217 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500218 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000220 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221 {static_assert(!is_reference<_Hp>::value,
222 "Attempted to default construct a reference element in a tuple");}
223
224 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500225 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000227 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228 {static_assert(!is_reference<_Hp>::value,
229 "Attempted to default construct a reference element in a tuple");}
230
Howard Hinnant693fc212010-09-27 17:54:17 +0000231 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000232 class = _EnableIf<
233 _And<
234 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
235 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000236 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000237 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000238 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000239 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000240 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000241 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000242 {static_assert(__can_bind_reference<_Tp&&>(),
243 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000244
245 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500246 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000248 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000249 {static_assert(__can_bind_reference<_Tp&&>(),
250 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251
252 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500253 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000255 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000256 {static_assert(!is_reference<_Hp>::value,
257 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000258
259 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500260 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000262 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000263 {static_assert(!is_reference<_Hp>::value,
264 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000265
Marshall Clow47fcee52014-04-21 23:48:09 +0000266 __tuple_leaf(const __tuple_leaf& __t) = default;
267 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500269 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000270 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000272 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273 return 0;
274 }
275
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000276 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
277 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278};
279
280template <size_t _Ip, class _Hp>
281class __tuple_leaf<_Ip, _Hp, true>
282 : private _Hp
283{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500284 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285 __tuple_leaf& operator=(const __tuple_leaf&);
286public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500287 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000288 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289
290 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500291 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
293
294 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500295 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
297 : _Hp(allocator_arg_t(), __a) {}
298
299 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500300 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
302 : _Hp(__a) {}
303
Howard Hinnant693fc212010-09-27 17:54:17 +0000304 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000305 class = _EnableIf<
306 _And<
307 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
308 is_constructible<_Hp, _Tp>
309 >::value
310 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000311 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000312 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000313 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000314 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315
316 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500317 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000318 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000319 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320
321 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500322 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000323 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000324 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325
326 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500327 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000328 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000329 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000331 __tuple_leaf(__tuple_leaf const &) = default;
332 __tuple_leaf(__tuple_leaf &&) = default;
333
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500334 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000335 int
336 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000337 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000338 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339 return 0;
340 }
341
Marshall Clow2229cee2013-07-22 16:02:19 +0000342 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
343 _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 +0000344};
345
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000346template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500347_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000348void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349
Marshall Clowc470eae2014-10-15 10:33:02 +0000350template <class _Tp>
351struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000352
Marshall Clowc470eae2014-10-15 10:33:02 +0000353template <class ..._Tp>
354struct __all_default_constructible<__tuple_types<_Tp...>>
355 : __all<is_default_constructible<_Tp>::value...>
356{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000357
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358// __tuple_impl
359
360template<class _Indx, class ..._Tp> struct __tuple_impl;
361
362template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000363struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364 : public __tuple_leaf<_Indx, _Tp>...
365{
Howard Hinnant38469632012-07-06 20:39:45 +0000366 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500367 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000368 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000369
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370 template <size_t ..._Uf, class ..._Tf,
371 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000372 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373 explicit
374 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
375 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000376 _Up&&... __u)
377 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
378 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000379 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000380 __tuple_leaf<_Ul, _Tl>()...
381 {}
382
383 template <class _Alloc, size_t ..._Uf, class ..._Tf,
384 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500385 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386 explicit
387 __tuple_impl(allocator_arg_t, const _Alloc& __a,
388 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
389 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
390 _Up&&... __u) :
391 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000392 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
394 {}
395
396 template <class _Tuple,
397 class = typename enable_if
398 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000399 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400 >::type
401 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000402 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000403 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
404 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000405 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
406 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407 {}
408
409 template <class _Alloc, class _Tuple,
410 class = typename enable_if
411 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000412 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413 >::type
414 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500415 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
417 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000418 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000419 _VSTD::forward<typename tuple_element<_Indx,
420 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421 {}
422
Howard Hinnant0d032d12013-11-06 17:45:43 +0000423 __tuple_impl(const __tuple_impl&) = default;
424 __tuple_impl(__tuple_impl&&) = default;
425
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500426 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000428 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400430 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431 }
432};
433
Louis Dionne6c0d5342018-07-31 11:56:20 -0400434template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500435_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400436void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
437 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
438}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000439
Louis Dionne6c0d5342018-07-31 11:56:20 -0400440template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500441_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400442void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
443 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500444 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400445 ), void(), 0)...);
446}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000447
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000449class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000451 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000453 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000454
Marshall Clow0abb1042013-07-17 18:25:36 +0000455 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000456 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000457 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000458 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000459 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000460 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000461 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
462 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500464 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000465
Louis Dionne574e2e32021-02-10 16:19:50 -0500466 // tuple() constructors (including allocator_arg_t variants)
467 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, _EnableIf<
468 _And<
469 _IsImpDefault<_Tp>... // explicit check
470 >::value
471 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400472 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000473 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500474 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
475 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000476
Louis Dionne574e2e32021-02-10 16:19:50 -0500477 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
478 template<class...> class _IsDefault = is_default_constructible, _EnableIf<
479 _And<
480 _IsDefault<_Tp>...,
481 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
482 >::value
483 , int> = 0>
484 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
485 explicit tuple()
486 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
487 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000488
Louis Dionne574e2e32021-02-10 16:19:50 -0500489 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, _EnableIf<
490 _And<
491 _IsImpDefault<_Tp>... // explicit check
492 >::value
493 , int> = 0>
494 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
495 tuple(allocator_arg_t, _Alloc const& __a)
496 : __base_(allocator_arg_t(), __a,
497 __tuple_indices<>(), __tuple_types<>(),
498 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
499 __tuple_types<_Tp...>()) {}
500
501 template <class _Alloc,
502 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
503 template<class...> class _IsDefault = is_default_constructible, _EnableIf<
504 _And<
505 _IsDefault<_Tp>...,
506 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
507 >::value
508 , int> = 0>
509 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
510 explicit tuple(allocator_arg_t, _Alloc const& __a)
511 : __base_(allocator_arg_t(), __a,
512 __tuple_indices<>(), __tuple_types<>(),
513 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
514 __tuple_types<_Tp...>()) {}
515
516 // tuple(const T&...) constructors (including allocator_arg_t variants)
517 template <template<class...> class _And = _And, _EnableIf<
518 _And<
519 _BoolConstant<sizeof...(_Tp) >= 1>,
520 is_copy_constructible<_Tp>...,
521 is_convertible<const _Tp&, _Tp>... // explicit check
522 >::value
523 , int> = 0>
524 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
525 tuple(const _Tp& ... __t)
526 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
527 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
528 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
529 typename __make_tuple_indices<0>::type(),
530 typename __make_tuple_types<tuple, 0>::type(),
531 __t...
532 ) {}
533
534 template <template<class...> class _And = _And, _EnableIf<
535 _And<
536 _BoolConstant<sizeof...(_Tp) >= 1>,
537 is_copy_constructible<_Tp>...,
538 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
539 >::value
540 , int> = 0>
541 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
542 explicit tuple(const _Tp& ... __t)
543 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
544 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
545 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
546 typename __make_tuple_indices<0>::type(),
547 typename __make_tuple_types<tuple, 0>::type(),
548 __t...
549 ) {}
550
551 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
552 _And<
553 _BoolConstant<sizeof...(_Tp) >= 1>,
554 is_copy_constructible<_Tp>...,
555 is_convertible<const _Tp&, _Tp>... // explicit check
556 >::value
557 , int> = 0>
558 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
559 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
560 : __base_(allocator_arg_t(), __a,
561 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
562 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
563 typename __make_tuple_indices<0>::type(),
564 typename __make_tuple_types<tuple, 0>::type(),
565 __t...
566 ) {}
567
568 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
569 _And<
570 _BoolConstant<sizeof...(_Tp) >= 1>,
571 is_copy_constructible<_Tp>...,
572 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
573 >::value
574 , int> = 0>
575 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
576 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
577 : __base_(allocator_arg_t(), __a,
578 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
579 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
580 typename __make_tuple_indices<0>::type(),
581 typename __make_tuple_types<tuple, 0>::type(),
582 __t...
583 ) {}
584
585 // tuple(U&& ...) constructors (including allocator_arg_t variants)
586 template <class ..._Up> struct _IsThisTuple : false_type { };
587 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
588
589 template <class ..._Up>
590 struct _EnableUTypesCtor : _And<
591 _BoolConstant<sizeof...(_Tp) >= 1>,
592 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
593 is_constructible<_Tp, _Up>...
594 > { };
595
596 template <class ..._Up, _EnableIf<
597 _And<
598 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
599 _EnableUTypesCtor<_Up...>,
600 is_convertible<_Up, _Tp>... // explicit check
601 >::value
602 , int> = 0>
603 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
604 tuple(_Up&&... __u)
605 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
606 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
607 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
608 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
609 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
610 _VSTD::forward<_Up>(__u)...) {}
611
612 template <class ..._Up, _EnableIf<
613 _And<
614 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
615 _EnableUTypesCtor<_Up...>,
616 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
617 >::value
618 , int> = 0>
619 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
620 explicit tuple(_Up&&... __u)
621 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
622 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
623 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
624 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
625 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
626 _VSTD::forward<_Up>(__u)...) {}
627
628 template <class _Alloc, class ..._Up, _EnableIf<
629 _And<
630 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
631 _EnableUTypesCtor<_Up...>,
632 is_convertible<_Up, _Tp>... // explicit check
633 >::value
634 , int> = 0>
635 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
636 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
637 : __base_(allocator_arg_t(), __a,
638 typename __make_tuple_indices<sizeof...(_Up)>::type(),
639 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
640 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
641 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
642 _VSTD::forward<_Up>(__u)...) {}
643
644 template <class _Alloc, class ..._Up, _EnableIf<
645 _And<
646 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
647 _EnableUTypesCtor<_Up...>,
648 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
649 >::value
650 , int> = 0>
651 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
652 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
653 : __base_(allocator_arg_t(), __a,
654 typename __make_tuple_indices<sizeof...(_Up)>::type(),
655 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
656 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
657 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
658 _VSTD::forward<_Up>(__u)...) {}
659
660 // Copy and move constructors (including the allocator_arg_t variants)
661 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000662 tuple(tuple&&) = default;
663
Louis Dionne574e2e32021-02-10 16:19:50 -0500664 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
665 _And<is_copy_constructible<_Tp>...>::value
666 , int> = 0>
667 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
668 : __base_(allocator_arg_t(), __alloc, __t)
669 { }
670
671 template <class _Alloc, template<class...> class _And = _And, _EnableIf<
672 _And<is_move_constructible<_Tp>...>::value
673 , int> = 0>
674 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
675 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
676 { }
677
678 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
679 template <class ..._Up>
680 struct _EnableCopyFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400681 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
682 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500683 _BoolConstant<sizeof...(_Tp) != 1>,
684 // _Tp and _Up are 1-element packs - the pack expansions look
685 // weird to avoid tripping up the type traits in degenerate cases
686 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500687 _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
688 _Not<is_constructible<_Tp, const tuple<_Up>&> >...
689 >
690 >,
691 is_constructible<_Tp, const _Up&>...
692 > { };
693
694 template <class ..._Up, _EnableIf<
695 _And<
696 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
697 _EnableCopyFromOtherTuple<_Up...>,
698 is_convertible<const _Up&, _Tp>... // explicit check
699 >::value
700 , int> = 0>
701 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
702 tuple(const tuple<_Up...>& __t)
703 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
704 : __base_(__t)
705 { }
706
707 template <class ..._Up, _EnableIf<
708 _And<
709 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
710 _EnableCopyFromOtherTuple<_Up...>,
711 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
712 >::value
713 , int> = 0>
714 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
715 explicit tuple(const tuple<_Up...>& __t)
716 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
717 : __base_(__t)
718 { }
719
720 template <class ..._Up, class _Alloc, _EnableIf<
721 _And<
722 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
723 _EnableCopyFromOtherTuple<_Up...>,
724 is_convertible<const _Up&, _Tp>... // explicit check
725 >::value
726 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500727 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500728 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
729 : __base_(allocator_arg_t(), __a, __t)
730 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000731
Louis Dionne574e2e32021-02-10 16:19:50 -0500732 template <class ..._Up, class _Alloc, _EnableIf<
733 _And<
734 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
735 _EnableCopyFromOtherTuple<_Up...>,
736 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
737 >::value
738 , int> = 0>
739 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
740 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
741 : __base_(allocator_arg_t(), __a, __t)
742 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000743
Louis Dionne574e2e32021-02-10 16:19:50 -0500744 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
745 template <class ..._Up>
746 struct _EnableMoveFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400747 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
748 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500749 _BoolConstant<sizeof...(_Tp) != 1>,
750 // _Tp and _Up are 1-element packs - the pack expansions look
751 // weird to avoid tripping up the type traits in degenerate cases
752 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500753 _Not<is_convertible<tuple<_Up>, _Tp> >...,
754 _Not<is_constructible<_Tp, tuple<_Up> > >...
755 >
756 >,
757 is_constructible<_Tp, _Up>...
758 > { };
759
760 template <class ..._Up, _EnableIf<
761 _And<
762 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
763 _EnableMoveFromOtherTuple<_Up...>,
764 is_convertible<_Up, _Tp>... // explicit check
765 >::value
766 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000767 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500768 tuple(tuple<_Up...>&& __t)
769 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
770 : __base_(_VSTD::move(__t))
771 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772
Louis Dionne574e2e32021-02-10 16:19:50 -0500773 template <class ..._Up, _EnableIf<
774 _And<
775 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
776 _EnableMoveFromOtherTuple<_Up...>,
777 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
778 >::value
779 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000780 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500781 explicit tuple(tuple<_Up...>&& __t)
782 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
783 : __base_(_VSTD::move(__t))
784 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000785
Louis Dionne574e2e32021-02-10 16:19:50 -0500786 template <class _Alloc, class ..._Up, _EnableIf<
787 _And<
788 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
789 _EnableMoveFromOtherTuple<_Up...>,
790 is_convertible<_Up, _Tp>... // explicit check
791 >::value
792 , int> = 0>
793 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
794 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
795 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
796 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797
Louis Dionne574e2e32021-02-10 16:19:50 -0500798 template <class _Alloc, class ..._Up, _EnableIf<
799 _And<
800 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
801 _EnableMoveFromOtherTuple<_Up...>,
802 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
803 >::value
804 , int> = 0>
805 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
806 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
807 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
808 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000809
Louis Dionne574e2e32021-02-10 16:19:50 -0500810 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
811 template <class _Up1, class _Up2, class ..._DependentTp>
812 struct _EnableImplicitCopyFromPair : _And<
813 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
814 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
815 is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
816 is_convertible<const _Up2&, _SecondType<_DependentTp...> >
817 > { };
Howard Hinnant65704d02012-04-01 23:10:42 +0000818
Louis Dionne574e2e32021-02-10 16:19:50 -0500819 template <class _Up1, class _Up2, class ..._DependentTp>
820 struct _EnableExplicitCopyFromPair : _And<
821 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
822 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
823 _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
824 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
825 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826
Louis Dionne574e2e32021-02-10 16:19:50 -0500827 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
828 _And<
829 _BoolConstant<sizeof...(_Tp) == 2>,
830 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
831 >::value
832 , int> = 0>
833 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
834 tuple(const pair<_Up1, _Up2>& __p)
835 _NOEXCEPT_((_And<
836 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
837 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
838 >::value))
839 : __base_(__p)
840 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841
Louis Dionne574e2e32021-02-10 16:19:50 -0500842 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
843 _And<
844 _BoolConstant<sizeof...(_Tp) == 2>,
845 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
846 >::value
847 , int> = 0>
848 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
849 explicit tuple(const pair<_Up1, _Up2>& __p)
850 _NOEXCEPT_((_And<
851 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
852 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
853 >::value))
854 : __base_(__p)
855 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000856
Louis Dionne574e2e32021-02-10 16:19:50 -0500857 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
858 _And<
859 _BoolConstant<sizeof...(_Tp) == 2>,
860 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
861 >::value
862 , int> = 0>
863 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
864 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
865 : __base_(allocator_arg_t(), __a, __p)
866 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867
Louis Dionne574e2e32021-02-10 16:19:50 -0500868 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
869 _And<
870 _BoolConstant<sizeof...(_Tp) == 2>,
871 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
872 >::value
873 , int> = 0>
874 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
875 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
876 : __base_(allocator_arg_t(), __a, __p)
877 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000878
Louis Dionne574e2e32021-02-10 16:19:50 -0500879 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
880 template <class _Up1, class _Up2, class ..._DependentTp>
881 struct _EnableImplicitMoveFromPair : _And<
882 is_constructible<_FirstType<_DependentTp...>, _Up1>,
883 is_constructible<_SecondType<_DependentTp...>, _Up2>,
884 is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
885 is_convertible<_Up2, _SecondType<_DependentTp...> >
886 > { };
Eric Fiselierec5a2102019-07-12 23:01:48 +0000887
Louis Dionne574e2e32021-02-10 16:19:50 -0500888 template <class _Up1, class _Up2, class ..._DependentTp>
889 struct _EnableExplicitMoveFromPair : _And<
890 is_constructible<_FirstType<_DependentTp...>, _Up1>,
891 is_constructible<_SecondType<_DependentTp...>, _Up2>,
892 _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
893 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
894 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895
Louis Dionne574e2e32021-02-10 16:19:50 -0500896 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
897 _And<
898 _BoolConstant<sizeof...(_Tp) == 2>,
899 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
900 >::value
901 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400902 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500903 tuple(pair<_Up1, _Up2>&& __p)
904 _NOEXCEPT_((_And<
905 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
906 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
907 >::value))
908 : __base_(_VSTD::move(__p))
909 { }
910
911 template <class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
912 _And<
913 _BoolConstant<sizeof...(_Tp) == 2>,
914 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
915 >::value
916 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400917 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500918 explicit tuple(pair<_Up1, _Up2>&& __p)
919 _NOEXCEPT_((_And<
920 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
921 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
922 >::value))
923 : __base_(_VSTD::move(__p))
924 { }
925
926 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
927 _And<
928 _BoolConstant<sizeof...(_Tp) == 2>,
929 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
930 >::value
931 , int> = 0>
932 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
933 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
934 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
935 { }
936
937 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, _EnableIf<
938 _And<
939 _BoolConstant<sizeof...(_Tp) == 2>,
940 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
941 >::value
942 , int> = 0>
943 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
944 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
945 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
946 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000947
Louis Dionne6c0d5342018-07-31 11:56:20 -0400948 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500949 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400950 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
951 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000952 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400953 _VSTD::__memberwise_copy_assign(*this, __tuple,
954 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000955 return *this;
956 }
957
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500958 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400959 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
960 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000961 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400962 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
963 __tuple_types<_Tp...>(),
964 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000965 return *this;
966 }
967
Louis Dionne6c0d5342018-07-31 11:56:20 -0400968 template<class... _Up, _EnableIf<
969 _And<
970 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
971 is_assignable<_Tp&, _Up const&>...
972 >::value
973 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500974 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400975 tuple& operator=(tuple<_Up...> const& __tuple)
976 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
977 {
978 _VSTD::__memberwise_copy_assign(*this, __tuple,
979 typename __make_tuple_indices<sizeof...(_Tp)>::type());
980 return *this;
981 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982
Louis Dionne6c0d5342018-07-31 11:56:20 -0400983 template<class... _Up, _EnableIf<
984 _And<
985 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
986 is_assignable<_Tp&, _Up>...
987 >::value
988 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500989 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400990 tuple& operator=(tuple<_Up...>&& __tuple)
991 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
992 {
993 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
994 __tuple_types<_Up...>(),
995 typename __make_tuple_indices<sizeof...(_Tp)>::type());
996 return *this;
997 }
998
999 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
1000 _And<_Dep,
1001 _BoolConstant<sizeof...(_Tp) == 2>,
1002 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1003 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1004 >::value
1005 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001006 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001007 tuple& operator=(pair<_Up1, _Up2> const& __pair)
1008 _NOEXCEPT_((_And<
1009 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1010 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1011 >::value))
1012 {
1013 _VSTD::get<0>(*this) = __pair.first;
1014 _VSTD::get<1>(*this) = __pair.second;
1015 return *this;
1016 }
1017
1018 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
1019 _And<_Dep,
1020 _BoolConstant<sizeof...(_Tp) == 2>,
1021 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1022 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1023 >::value
1024 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001025 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001026 tuple& operator=(pair<_Up1, _Up2>&& __pair)
1027 _NOEXCEPT_((_And<
1028 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1029 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1030 >::value))
1031 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001032 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1033 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001034 return *this;
1035 }
1036
1037 // EXTENSION
1038 template<class _Up, size_t _Np, class = _EnableIf<
1039 _And<
1040 _BoolConstant<_Np == sizeof...(_Tp)>,
1041 is_assignable<_Tp&, _Up const&>...
1042 >::value
1043 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001044 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001045 tuple& operator=(array<_Up, _Np> const& __array)
1046 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1047 {
1048 _VSTD::__memberwise_copy_assign(*this, __array,
1049 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1050 return *this;
1051 }
1052
1053 // EXTENSION
1054 template<class _Up, size_t _Np, class = void, class = _EnableIf<
1055 _And<
1056 _BoolConstant<_Np == sizeof...(_Tp)>,
1057 is_assignable<_Tp&, _Up>...
1058 >::value
1059 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001060 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001061 tuple& operator=(array<_Up, _Np>&& __array)
1062 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1063 {
1064 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1065 __tuple_types<_If<true, _Up, _Tp>...>(),
1066 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1067 return *this;
1068 }
1069
1070 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001071 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001072 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001073 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074};
1075
1076template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001077class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078{
1079public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001080 _LIBCPP_INLINE_VISIBILITY constexpr
1081 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001082 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001083 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001084 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001086 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001087 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001088 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001089 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001090 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001091 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001092 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001093 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001095 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096};
1097
Eric Fiselier8df4ac62017-10-04 00:04:26 +00001098#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Louis Dionne616da2a2019-08-12 18:30:31 +00001099template <class ..._Tp>
1100tuple(_Tp...) -> tuple<_Tp...>;
1101template <class _Tp1, class _Tp2>
1102tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1103template <class _Alloc, class ..._Tp>
1104tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1105template <class _Alloc, class _Tp1, class _Tp2>
1106tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1107template <class _Alloc, class ..._Tp>
1108tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001109#endif
1110
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001112inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001113typename enable_if
1114<
1115 __all<__is_swappable<_Tp>::value...>::value,
1116 void
1117>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001118swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1119 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1120 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001121
1122// get
1123
1124template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001125inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001126typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001127get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001129 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001130 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001131}
1132
1133template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001134inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001135const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001136get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001138 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001139 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140}
1141
Howard Hinnant22e97242010-11-17 19:52:17 +00001142template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001143inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001144typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001145get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001146{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001147 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001148 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001149 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001150}
1151
Eric Fiselier6dea8092015-12-18 00:36:55 +00001152template <size_t _Ip, class ..._Tp>
1153inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1154const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1155get(const tuple<_Tp...>&& __t) _NOEXCEPT
1156{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001157 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001158 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001159 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001160}
1161
Marshall Clow15b02e02013-07-13 02:54:05 +00001162#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001163
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001164namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001165
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001166static constexpr size_t __not_found = -1;
1167static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001168
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001169inline _LIBCPP_INLINE_VISIBILITY
1170constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1171 return !__matches ? __res :
1172 (__res == __not_found ? __curr_i : __ambiguous);
1173}
Marshall Clow15b02e02013-07-13 02:54:05 +00001174
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001175template <size_t _Nx>
1176inline _LIBCPP_INLINE_VISIBILITY
1177constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1178 return __i == _Nx ? __not_found :
1179 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1180}
1181
1182template <class _T1, class ..._Args>
1183struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001184 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001185 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001186 static_assert(value != __not_found, "type not found in type list" );
1187 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001188};
1189
Eric Fiselier8087d302016-07-02 03:46:08 +00001190template <class _T1>
1191struct __find_exactly_one_checked<_T1> {
1192 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1193};
1194
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001195} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001196
1197template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001198struct __find_exactly_one_t
1199 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1200};
Marshall Clow15b02e02013-07-13 02:54:05 +00001201
1202template <class _T1, class... _Args>
1203inline _LIBCPP_INLINE_VISIBILITY
1204constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1205{
1206 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1207}
1208
1209template <class _T1, class... _Args>
1210inline _LIBCPP_INLINE_VISIBILITY
1211constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1212{
1213 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1214}
1215
1216template <class _T1, class... _Args>
1217inline _LIBCPP_INLINE_VISIBILITY
1218constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1219{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001220 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001221}
1222
Eric Fiselier6dea8092015-12-18 00:36:55 +00001223template <class _T1, class... _Args>
1224inline _LIBCPP_INLINE_VISIBILITY
1225constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1226{
1227 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1228}
1229
Marshall Clow15b02e02013-07-13 02:54:05 +00001230#endif
1231
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232// tie
1233
1234template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001235inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001236tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001237tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238{
1239 return tuple<_Tp&...>(__t...);
1240}
1241
1242template <class _Up>
1243struct __ignore_t
1244{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001245 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001246 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1247 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248};
1249
Eric Fiselier24e70262017-02-06 01:25:31 +00001250namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001251 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001252}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001255inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001256tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257make_tuple(_Tp&&... __t)
1258{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001259 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260}
1261
Howard Hinnant3d203a32010-08-19 18:59:38 +00001262template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001263inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1264tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001265forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001266{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001267 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001268}
1269
Howard Hinnantc834c512011-11-29 18:15:50 +00001270template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001271struct __tuple_equal
1272{
1273 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001274 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275 bool operator()(const _Tp& __x, const _Up& __y)
1276 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001277 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278 }
1279};
1280
1281template <>
1282struct __tuple_equal<0>
1283{
1284 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001285 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286 bool operator()(const _Tp&, const _Up&)
1287 {
1288 return true;
1289 }
1290};
1291
1292template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001293inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294bool
1295operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1296{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001297 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001298 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1299}
1300
1301template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001302inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303bool
1304operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1305{
1306 return !(__x == __y);
1307}
1308
Howard Hinnantc834c512011-11-29 18:15:50 +00001309template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310struct __tuple_less
1311{
1312 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001313 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314 bool operator()(const _Tp& __x, const _Up& __y)
1315 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001316 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1317 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1318 return true;
1319 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1320 return false;
1321 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001322 }
1323};
1324
1325template <>
1326struct __tuple_less<0>
1327{
1328 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001329 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001330 bool operator()(const _Tp&, const _Up&)
1331 {
1332 return false;
1333 }
1334};
1335
1336template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001337inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001338bool
1339operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1340{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001341 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001342 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1343}
1344
1345template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001346inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001347bool
1348operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1349{
1350 return __y < __x;
1351}
1352
1353template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001354inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001355bool
1356operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1357{
1358 return !(__x < __y);
1359}
1360
1361template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001362inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363bool
1364operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1365{
1366 return !(__y < __x);
1367}
1368
1369// tuple_cat
1370
Howard Hinnant6256ee72010-12-11 20:47:50 +00001371template <class _Tp, class _Up> struct __tuple_cat_type;
1372
1373template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001374struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001376 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001377};
1378
1379template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1380struct __tuple_cat_return_1
1381{
1382};
1383
1384template <class ..._Types, class _Tuple0>
1385struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1386{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001387 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001388 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001389 type;
1390};
1391
1392template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1393struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1394 : public __tuple_cat_return_1<
1395 typename __tuple_cat_type<
1396 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001397 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001398 >::type,
1399 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1400 _Tuple1, _Tuples...>
1401{
1402};
1403
1404template <class ..._Tuples> struct __tuple_cat_return;
1405
1406template <class _Tuple0, class ..._Tuples>
1407struct __tuple_cat_return<_Tuple0, _Tuples...>
1408 : public __tuple_cat_return_1<tuple<>,
1409 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1410 _Tuples...>
1411{
1412};
1413
1414template <>
1415struct __tuple_cat_return<>
1416{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001417 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001418};
1419
Marshall Clow2229cee2013-07-22 16:02:19 +00001420inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001421tuple<>
1422tuple_cat()
1423{
1424 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001425}
1426
Howard Hinnantc834c512011-11-29 18:15:50 +00001427template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001428struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001429
Howard Hinnant21376f62010-12-12 23:04:37 +00001430template <class ..._Types, size_t ..._I0, class _Tuple0>
1431struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001433 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001434 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1435 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1436};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437
Howard Hinnant21376f62010-12-12 23:04:37 +00001438template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1439struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1440 _Tuple0, _Tuple1, _Tuples...>
1441 : public __tuple_cat_return_ref_imp<
1442 tuple<_Types..., typename __apply_cv<_Tuple0,
1443 typename tuple_element<_I0,
1444 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1445 typename __make_tuple_indices<tuple_size<typename
1446 remove_reference<_Tuple1>::type>::value>::type,
1447 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001448{
Howard Hinnant21376f62010-12-12 23:04:37 +00001449};
1450
1451template <class _Tuple0, class ..._Tuples>
1452struct __tuple_cat_return_ref
1453 : public __tuple_cat_return_ref_imp<tuple<>,
1454 typename __make_tuple_indices<
1455 tuple_size<typename remove_reference<_Tuple0>::type>::value
1456 >::type, _Tuple0, _Tuples...>
1457{
1458};
1459
1460template <class _Types, class _I0, class _J0>
1461struct __tuple_cat;
1462
1463template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001464struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001465{
1466 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001467 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001468 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1469 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1470 {
David Blaikie699a5e22019-10-28 18:03:59 -07001471 return _VSTD::forward_as_tuple(
1472 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1473 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001474 }
1475
1476 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001477 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001478 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1479 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1480 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001481 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1482 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001483 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001484 tuple<_Types...,
1485 typename __apply_cv<_Tuple0, typename tuple_element<
1486 _J0, _T0>::type>::type&&...>,
1487 typename __make_tuple_indices<sizeof...(_Types) +
1488 tuple_size<_T0>::value>::type,
1489 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1490 _VSTD::forward_as_tuple(
1491 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1492 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1493 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001494 }
1495};
1496
1497template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001498inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001499typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1500tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1501{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001502 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001503 return __tuple_cat<tuple<>, __tuple_indices<>,
1504 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001505 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1506 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507}
1508
1509template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001510struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511 : true_type {};
1512
Howard Hinnantc51e1022010-05-11 19:42:16 +00001513template <class _T1, class _T2>
1514template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001515inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516pair<_T1, _T2>::pair(piecewise_construct_t,
1517 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1518 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001519 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1520 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001521{
1522}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001523
Eric Fiselier8e892c52016-07-18 00:35:56 +00001524#if _LIBCPP_STD_VER > 14
1525template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001526_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001527
1528#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1529
1530template <class _Fn, class _Tuple, size_t ..._Id>
1531inline _LIBCPP_INLINE_VISIBILITY
1532constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1533 __tuple_indices<_Id...>)
1534_LIBCPP_NOEXCEPT_RETURN(
1535 _VSTD::__invoke_constexpr(
1536 _VSTD::forward<_Fn>(__f),
1537 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1538)
1539
1540template <class _Fn, class _Tuple>
1541inline _LIBCPP_INLINE_VISIBILITY
1542constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1543_LIBCPP_NOEXCEPT_RETURN(
1544 _VSTD::__apply_tuple_impl(
1545 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001546 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001547)
1548
1549template <class _Tp, class _Tuple, size_t... _Idx>
1550inline _LIBCPP_INLINE_VISIBILITY
1551constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1552_LIBCPP_NOEXCEPT_RETURN(
1553 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1554)
1555
1556template <class _Tp, class _Tuple>
1557inline _LIBCPP_INLINE_VISIBILITY
1558constexpr _Tp make_from_tuple(_Tuple&& __t)
1559_LIBCPP_NOEXCEPT_RETURN(
1560 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001561 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001562)
1563
1564#undef _LIBCPP_NOEXCEPT_RETURN
1565
1566#endif // _LIBCPP_STD_VER > 14
1567
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001568#endif // !defined(_LIBCPP_CXX03_LANG)
1569
Howard Hinnantc51e1022010-05-11 19:42:16 +00001570_LIBCPP_END_NAMESPACE_STD
1571
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001572#endif // _LIBCPP_TUPLE