blob: 6e07892f94791ec02f70ad42d7e983e4e703a46e [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>
153#include <__tuple>
154#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000156#include <__functional_base>
157#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000158#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000160#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000162#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163
164_LIBCPP_BEGIN_NAMESPACE_STD
165
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000166#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167
Marshall Clowf50d66f2014-03-03 06:18:11 +0000168
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169// __tuple_leaf
170
Eric Fiselierf7394302015-06-13 07:08:02 +0000171template <size_t _Ip, class _Hp,
172 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000173 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174class __tuple_leaf;
175
176template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500177inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000179 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180{
181 swap(__x.get(), __y.get());
182}
183
184template <size_t _Ip, class _Hp, bool>
185class __tuple_leaf
186{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000187 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188
Eric Fiselierca8bba12016-07-20 02:57:39 +0000189 template <class _Tp>
190 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000191#if __has_keyword(__reference_binds_to_temporary)
192 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000193#else
194 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000195#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000196 }
197
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500198 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000199 __tuple_leaf& operator=(const __tuple_leaf&);
200public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500201 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000202 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203 {static_assert(!is_reference<_Hp>::value,
204 "Attempted to default construct a reference element in a tuple");}
205
206 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500207 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000209 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210 {static_assert(!is_reference<_Hp>::value,
211 "Attempted to default construct a reference element in a tuple");}
212
213 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500214 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000216 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217 {static_assert(!is_reference<_Hp>::value,
218 "Attempted to default construct a reference element in a tuple");}
219
220 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500221 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000222 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000223 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224 {static_assert(!is_reference<_Hp>::value,
225 "Attempted to default construct a reference element in a tuple");}
226
Howard Hinnant693fc212010-09-27 17:54:17 +0000227 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000228 class = _EnableIf<
229 _And<
230 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
231 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000232 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000233 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000234 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000235 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000236 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000237 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000238 {static_assert(__can_bind_reference<_Tp&&>(),
239 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240
241 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500242 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000244 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000245 {static_assert(__can_bind_reference<_Tp&&>(),
246 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247
248 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500249 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000251 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000252 {static_assert(!is_reference<_Hp>::value,
253 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254
255 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500256 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000258 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000259 {static_assert(!is_reference<_Hp>::value,
260 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261
Marshall Clow47fcee52014-04-21 23:48:09 +0000262 __tuple_leaf(const __tuple_leaf& __t) = default;
263 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500265 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000266 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000267 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000268 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000269 return 0;
270 }
271
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000272 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
273 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000274};
275
276template <size_t _Ip, class _Hp>
277class __tuple_leaf<_Ip, _Hp, true>
278 : private _Hp
279{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500280 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281 __tuple_leaf& operator=(const __tuple_leaf&);
282public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500283 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000284 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285
286 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500287 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
289
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, 1>, const _Alloc& __a)
293 : _Hp(allocator_arg_t(), __a) {}
294
295 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500296 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000297 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
298 : _Hp(__a) {}
299
Howard Hinnant693fc212010-09-27 17:54:17 +0000300 template <class _Tp,
Eric Fiselier3906a132019-06-23 20:28:29 +0000301 class = _EnableIf<
302 _And<
303 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
304 is_constructible<_Hp, _Tp>
305 >::value
306 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000307 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000308 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000309 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000310 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311
312 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500313 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000315 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316
317 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500318 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000319 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000320 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000321
322 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500323 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000325 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000327 __tuple_leaf(__tuple_leaf const &) = default;
328 __tuple_leaf(__tuple_leaf &&) = default;
329
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500330 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000331 int
332 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000333 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000334 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000335 return 0;
336 }
337
Marshall Clow2229cee2013-07-22 16:02:19 +0000338 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
339 _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 +0000340};
341
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000342template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500343_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000344void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345
Marshall Clowc470eae2014-10-15 10:33:02 +0000346template <class _Tp>
347struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000348
Marshall Clowc470eae2014-10-15 10:33:02 +0000349template <class ..._Tp>
350struct __all_default_constructible<__tuple_types<_Tp...>>
351 : __all<is_default_constructible<_Tp>::value...>
352{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000353
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354// __tuple_impl
355
356template<class _Indx, class ..._Tp> struct __tuple_impl;
357
358template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000359struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360 : public __tuple_leaf<_Indx, _Tp>...
361{
Howard Hinnant38469632012-07-06 20:39:45 +0000362 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500363 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000364 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000365
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 template <size_t ..._Uf, class ..._Tf,
367 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000368 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000369 explicit
370 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
371 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000372 _Up&&... __u)
373 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
374 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000375 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376 __tuple_leaf<_Ul, _Tl>()...
377 {}
378
379 template <class _Alloc, size_t ..._Uf, class ..._Tf,
380 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500381 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382 explicit
383 __tuple_impl(allocator_arg_t, const _Alloc& __a,
384 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
385 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
386 _Up&&... __u) :
387 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000388 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
390 {}
391
392 template <class _Tuple,
393 class = typename enable_if
394 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000395 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396 >::type
397 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000398 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000399 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
400 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000401 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
402 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403 {}
404
405 template <class _Alloc, class _Tuple,
406 class = typename enable_if
407 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000408 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 >::type
410 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500411 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
413 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000414 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000415 _VSTD::forward<typename tuple_element<_Indx,
416 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000417 {}
418
Howard Hinnant0d032d12013-11-06 17:45:43 +0000419 __tuple_impl(const __tuple_impl&) = default;
420 __tuple_impl(__tuple_impl&&) = default;
421
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500422 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000424 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400426 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427 }
428};
429
Louis Dionne6c0d5342018-07-31 11:56:20 -0400430template<class _Dest, class _Source, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500431_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400432void __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
433 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
434}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000435
Louis Dionne6c0d5342018-07-31 11:56:20 -0400436template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500437_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400438void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
439 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500440 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400441 ), void(), 0)...);
442}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000443
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000445class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000447 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000449 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450
Eric Fiselier41b686e2016-12-08 23:57:08 +0000451#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
452 static constexpr bool _EnableImplicitReducedArityExtension = true;
453#else
454 static constexpr bool _EnableImplicitReducedArityExtension = false;
455#endif
456
Eric Fiselier264d04a2016-04-15 18:05:59 +0000457 template <class ..._Args>
458 struct _PackExpandsToThisTuple : false_type {};
459
460 template <class _Arg>
461 struct _PackExpandsToThisTuple<_Arg>
462 : is_same<typename __uncvref<_Arg>::type, tuple> {};
463
464 template <bool _MaybeEnable, class _Dummy = void>
465 struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
466
467 template <class _Dummy>
468 struct _CheckArgsConstructor<true, _Dummy>
469 {
Eric Fiselier18d72a02019-09-30 20:55:30 +0000470 template <int&...>
471 static constexpr bool __enable_implicit_default() {
472 return __all<__is_implicitly_default_constructible<_Tp>::value... >::value;
473 }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000474
Eric Fiselier18d72a02019-09-30 20:55:30 +0000475 template <int&...>
476 static constexpr bool __enable_explicit_default() {
477 return
478 __all<is_default_constructible<_Tp>::value...>::value &&
479 !__enable_implicit_default< >();
480 }
481
Eric Fiseliere61db632016-07-25 04:32:07 +0000482
483 template <class ..._Args>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000484 static constexpr bool __enable_explicit() {
485 return
486 __tuple_constructible<
487 tuple<_Args...>,
488 typename __make_tuple_types<tuple,
489 sizeof...(_Args) < sizeof...(_Tp) ?
490 sizeof...(_Args) :
491 sizeof...(_Tp)>::type
492 >::value &&
493 !__tuple_convertible<
494 tuple<_Args...>,
495 typename __make_tuple_types<tuple,
496 sizeof...(_Args) < sizeof...(_Tp) ?
497 sizeof...(_Args) :
498 sizeof...(_Tp)>::type
499 >::value &&
500 __all_default_constructible<
501 typename __make_tuple_types<tuple, sizeof...(_Tp),
502 sizeof...(_Args) < sizeof...(_Tp) ?
503 sizeof...(_Args) :
504 sizeof...(_Tp)>::type
505 >::value;
506 }
507
508 template <class ..._Args>
509 static constexpr bool __enable_implicit() {
510 return
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000511 __tuple_constructible<
512 tuple<_Args...>,
513 typename __make_tuple_types<tuple,
514 sizeof...(_Args) < sizeof...(_Tp) ?
515 sizeof...(_Args) :
516 sizeof...(_Tp)>::type
517 >::value &&
Eric Fiselier264d04a2016-04-15 18:05:59 +0000518 __tuple_convertible<
519 tuple<_Args...>,
520 typename __make_tuple_types<tuple,
521 sizeof...(_Args) < sizeof...(_Tp) ?
522 sizeof...(_Args) :
523 sizeof...(_Tp)>::type
524 >::value &&
525 __all_default_constructible<
526 typename __make_tuple_types<tuple, sizeof...(_Tp),
527 sizeof...(_Args) < sizeof...(_Tp) ?
528 sizeof...(_Args) :
529 sizeof...(_Tp)>::type
530 >::value;
531 }
532 };
533
534 template <bool _MaybeEnable,
535 bool = sizeof...(_Tp) == 1,
536 class _Dummy = void>
537 struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
538
539 template <class _Dummy>
540 struct _CheckTupleLikeConstructor<true, false, _Dummy>
541 {
542 template <class _Tuple>
543 static constexpr bool __enable_implicit() {
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000544 return __tuple_constructible<_Tuple, tuple>::value
545 && __tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000546 }
547
548 template <class _Tuple>
549 static constexpr bool __enable_explicit() {
Eric Fiselierb3225562016-12-15 06:34:54 +0000550 return __tuple_constructible<_Tuple, tuple>::value
551 && !__tuple_convertible<_Tuple, tuple>::value;
Eric Fiselier264d04a2016-04-15 18:05:59 +0000552 }
553 };
554
555 template <class _Dummy>
556 struct _CheckTupleLikeConstructor<true, true, _Dummy>
557 {
558 // This trait is used to disable the tuple-like constructor when
559 // the UTypes... constructor should be selected instead.
560 // See LWG issue #2549.
561 template <class _Tuple>
Eric Fiselier3906a132019-06-23 20:28:29 +0000562 using _PreferTupleLikeConstructor = _Or<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000563 // Don't attempt the two checks below if the tuple we are given
564 // has the same type as this tuple.
Eric Fiselier3906a132019-06-23 20:28:29 +0000565 _IsSame<__uncvref_t<_Tuple>, tuple>,
566 _Lazy<_And,
567 _Not<is_constructible<_Tp..., _Tuple>>,
568 _Not<is_convertible<_Tuple, _Tp...>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000569 >
570 >;
571
572 template <class _Tuple>
573 static constexpr bool __enable_implicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000574 return _And<
Eric Fiselierd0dddc52019-07-03 19:21:40 +0000575 __tuple_constructible<_Tuple, tuple>,
Eric Fiselier264d04a2016-04-15 18:05:59 +0000576 __tuple_convertible<_Tuple, tuple>,
577 _PreferTupleLikeConstructor<_Tuple>
578 >::value;
579 }
580
581 template <class _Tuple>
582 static constexpr bool __enable_explicit() {
Eric Fiselier3906a132019-06-23 20:28:29 +0000583 return _And<
Eric Fiselier264d04a2016-04-15 18:05:59 +0000584 __tuple_constructible<_Tuple, tuple>,
585 _PreferTupleLikeConstructor<_Tuple>,
Eric Fiselier3906a132019-06-23 20:28:29 +0000586 _Not<__tuple_convertible<_Tuple, tuple>>
Eric Fiselier264d04a2016-04-15 18:05:59 +0000587 >::value;
588 }
589 };
590
Eric Fiselierec5a2102019-07-12 23:01:48 +0000591 template <class _Tuple, bool _DisableIfLValue>
592 using _EnableImplicitTupleLikeConstructor = _EnableIf<
593 _CheckTupleLikeConstructor<
594 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
595 && !_PackExpandsToThisTuple<_Tuple>::value
596 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
597 >::template __enable_implicit<_Tuple>(),
598 bool
599 >;
600
601 template <class _Tuple, bool _DisableIfLValue>
602 using _EnableExplicitTupleLikeConstructor = _EnableIf<
603 _CheckTupleLikeConstructor<
604 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
605 && !_PackExpandsToThisTuple<_Tuple>::value
606 && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
607 >::template __enable_explicit<_Tuple>(),
608 bool
609 >;
Marshall Clow0abb1042013-07-17 18:25:36 +0000610 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000611 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000612 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000613 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000614 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000615 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000616 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
617 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618public:
619
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000620 template <bool _Dummy = true, _EnableIf<
Eric Fiselier18d72a02019-09-30 20:55:30 +0000621 _CheckArgsConstructor<_Dummy>::__enable_implicit_default()
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000622 , void*> = nullptr>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500623 _LIBCPP_INLINE_VISIBILITY constexpr
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000624 tuple()
625 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
626
627 template <bool _Dummy = true, _EnableIf<
Eric Fiselier18d72a02019-09-30 20:55:30 +0000628 _CheckArgsConstructor<_Dummy>::__enable_explicit_default()
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000629 , void*> = nullptr>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500630 explicit _LIBCPP_INLINE_VISIBILITY constexpr
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000631 tuple()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000632 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000633
Eric Fiselier737a16d2016-07-25 02:36:42 +0000634 tuple(tuple const&) = default;
635 tuple(tuple&&) = default;
636
Eric Fiselier18d72a02019-09-30 20:55:30 +0000637 template <class _AllocArgT, class _Alloc, _EnableIf<
638 _CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value >::__enable_implicit_default()
Louis Dionne668a50c2019-09-27 15:06:52 +0000639 , void*> = nullptr
Eric Fiselier3906a132019-06-23 20:28:29 +0000640 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500641 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselierc170df52016-04-15 03:29:40 +0000642 tuple(_AllocArgT, _Alloc const& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000643 : __base_(allocator_arg_t(), __a,
Eric Fiselierc170df52016-04-15 03:29:40 +0000644 __tuple_indices<>(), __tuple_types<>(),
645 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
646 __tuple_types<_Tp...>()) {}
647
Eric Fiselier18d72a02019-09-30 20:55:30 +0000648 template <class _AllocArgT, class _Alloc, _EnableIf<
649 _CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value>::__enable_explicit_default()
Louis Dionne668a50c2019-09-27 15:06:52 +0000650 , void*> = nullptr
651 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500652 explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne668a50c2019-09-27 15:06:52 +0000653 tuple(_AllocArgT, _Alloc const& __a)
654 : __base_(allocator_arg_t(), __a,
655 __tuple_indices<>(), __tuple_types<>(),
656 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
657 __tuple_types<_Tp...>()) {}
658
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000659 template <bool _Dummy = true,
660 typename enable_if
661 <
662 _CheckArgsConstructor<
663 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000664 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000665 bool
666 >::type = false
667 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000668 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000669 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000670 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
672 typename __make_tuple_indices<0>::type(),
673 typename __make_tuple_types<tuple, 0>::type(),
674 __t...
675 ) {}
676
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000677 template <bool _Dummy = true,
678 typename enable_if
679 <
680 _CheckArgsConstructor<
681 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000682 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000683 bool
684 >::type = false
685 >
686 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
687 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000688 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000689 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
690 typename __make_tuple_indices<0>::type(),
691 typename __make_tuple_types<tuple, 0>::type(),
692 __t...
693 ) {}
694
695 template <class _Alloc, bool _Dummy = true,
696 typename enable_if
697 <
698 _CheckArgsConstructor<
699 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000700 >::template __enable_implicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000701 bool
702 >::type = false
703 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500704 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000706 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
708 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
709 typename __make_tuple_indices<0>::type(),
710 typename __make_tuple_types<tuple, 0>::type(),
711 __t...
712 ) {}
713
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000714 template <class _Alloc, bool _Dummy = true,
715 typename enable_if
716 <
717 _CheckArgsConstructor<
718 _Dummy
Eric Fiselieraa452d52016-11-13 19:54:31 +0000719 >::template __enable_explicit<_Tp const&...>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000720 bool
721 >::type = false
722 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500723 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000724 explicit
725 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000726 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000727 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
728 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
729 typename __make_tuple_indices<0>::type(),
730 typename __make_tuple_types<tuple, 0>::type(),
731 __t...
732 ) {}
733
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734 template <class ..._Up,
Eric Fiselier41b686e2016-12-08 23:57:08 +0000735 bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
Howard Hinnant65704d02012-04-01 23:10:42 +0000736 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000738 _CheckArgsConstructor<
Eric Fiselier41b686e2016-12-08 23:57:08 +0000739 sizeof...(_Up) == sizeof...(_Tp)
740 && !_PackIsTuple
741 >::template __enable_implicit<_Up...>() ||
742 _CheckArgsConstructor<
743 _EnableImplicitReducedArityExtension
744 && sizeof...(_Up) < sizeof...(_Tp)
745 && !_PackIsTuple
Eric Fiselier264d04a2016-04-15 18:05:59 +0000746 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000747 bool
748 >::type = false
749 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000750 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000751 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000752 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000753 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000754 typename __make_tuple_indices<sizeof...(_Up)>::type,
755 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
756 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
757 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
Marshall Clowcad20652014-09-16 17:08:21 +0000758 _Up...
Howard Hinnant62751642012-07-06 21:53:48 +0000759 >::value
760 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000761 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000762 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
763 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
764 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
765 _VSTD::forward<_Up>(__u)...) {}
766
767 template <class ..._Up,
768 typename enable_if
769 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000770 _CheckArgsConstructor<
771 sizeof...(_Up) <= sizeof...(_Tp)
772 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000773 >::template __enable_explicit<_Up...>() ||
774 _CheckArgsConstructor<
775 !_EnableImplicitReducedArityExtension
776 && sizeof...(_Up) < sizeof...(_Tp)
Eric Fiselieredbbd402017-02-04 22:57:01 +0000777 && !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier41b686e2016-12-08 23:57:08 +0000778 >::template __enable_implicit<_Up...>(),
Howard Hinnant65704d02012-04-01 23:10:42 +0000779 bool
Eric Fiselier264d04a2016-04-15 18:05:59 +0000780 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000782 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783 explicit
784 tuple(_Up&&... __u)
Howard Hinnant62751642012-07-06 21:53:48 +0000785 _NOEXCEPT_((
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000786 is_nothrow_constructible<_BaseT,
Howard Hinnant62751642012-07-06 21:53:48 +0000787 typename __make_tuple_indices<sizeof...(_Up)>::type,
788 typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
789 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
790 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
791 _Up...
792 >::value
793 ))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000794 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
796 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
797 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000798 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799
800 template <class _Alloc, class ..._Up,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000801 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000803 _CheckArgsConstructor<
804 sizeof...(_Up) == sizeof...(_Tp) &&
805 !_PackExpandsToThisTuple<_Up...>::value
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000806 >::template __enable_implicit<_Up...>(),
807 bool
808 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500810 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000811 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000812 : __base_(allocator_arg_t(), __a,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000813 typename __make_tuple_indices<sizeof...(_Up)>::type(),
814 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
815 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
816 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000817 _VSTD::forward<_Up>(__u)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000819 template <class _Alloc, class ..._Up,
820 typename enable_if
821 <
822 _CheckArgsConstructor<
823 sizeof...(_Up) == sizeof...(_Tp) &&
824 !_PackExpandsToThisTuple<_Up...>::value
825 >::template __enable_explicit<_Up...>(),
826 bool
827 >::type = false
828 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500829 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000830 explicit
831 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000832 : __base_(allocator_arg_t(), __a,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000833 typename __make_tuple_indices<sizeof...(_Up)>::type(),
834 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
835 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
836 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
837 _VSTD::forward<_Up>(__u)...) {}
838
Eric Fiselierec5a2102019-07-12 23:01:48 +0000839 template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000840 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000841 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
842 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843
Eric Fiselierec5a2102019-07-12 23:01:48 +0000844 template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false>
845 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
846 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
847 : __base_(__t) {}
848 template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false>
Marshall Clow2229cee2013-07-22 16:02:19 +0000849 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant65704d02012-04-01 23:10:42 +0000850 explicit
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000851 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
852 : __base_(_VSTD::forward<_Tuple>(__t)) {}
Howard Hinnant65704d02012-04-01 23:10:42 +0000853
Eric Fiselierec5a2102019-07-12 23:01:48 +0000854 template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false>
855 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
856 explicit
857 tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
858 : __base_(__t) {}
859
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 template <class _Alloc, class _Tuple,
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000861 typename enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +0000862 <
Eric Fiselier264d04a2016-04-15 18:05:59 +0000863 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000864 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
865 >::template __enable_implicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000866 bool
867 >::type = false
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500869 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000870 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000871 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000873 template <class _Alloc, class _Tuple,
874 typename enable_if
875 <
876 _CheckTupleLikeConstructor<
Eric Fiselierb3225562016-12-15 06:34:54 +0000877 __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
878 >::template __enable_explicit<_Tuple>(),
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000879 bool
880 >::type = false
881 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500882 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000883 explicit
884 tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000885 : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000886
Louis Dionne6c0d5342018-07-31 11:56:20 -0400887 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500888 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400889 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
890 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000891 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400892 _VSTD::__memberwise_copy_assign(*this, __tuple,
893 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000894 return *this;
895 }
896
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500897 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400898 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
899 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000900 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400901 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
902 __tuple_types<_Tp...>(),
903 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000904 return *this;
905 }
906
Louis Dionne6c0d5342018-07-31 11:56:20 -0400907 template<class... _Up, _EnableIf<
908 _And<
909 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
910 is_assignable<_Tp&, _Up const&>...
911 >::value
912 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500913 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400914 tuple& operator=(tuple<_Up...> const& __tuple)
915 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
916 {
917 _VSTD::__memberwise_copy_assign(*this, __tuple,
918 typename __make_tuple_indices<sizeof...(_Tp)>::type());
919 return *this;
920 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000921
Louis Dionne6c0d5342018-07-31 11:56:20 -0400922 template<class... _Up, _EnableIf<
923 _And<
924 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
925 is_assignable<_Tp&, _Up>...
926 >::value
927 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500928 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400929 tuple& operator=(tuple<_Up...>&& __tuple)
930 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
931 {
932 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
933 __tuple_types<_Up...>(),
934 typename __make_tuple_indices<sizeof...(_Tp)>::type());
935 return *this;
936 }
937
938 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
939 _And<_Dep,
940 _BoolConstant<sizeof...(_Tp) == 2>,
941 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
942 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
943 >::value
944 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500945 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400946 tuple& operator=(pair<_Up1, _Up2> const& __pair)
947 _NOEXCEPT_((_And<
948 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
949 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
950 >::value))
951 {
952 _VSTD::get<0>(*this) = __pair.first;
953 _VSTD::get<1>(*this) = __pair.second;
954 return *this;
955 }
956
957 template<class _Up1, class _Up2, class _Dep = true_type, _EnableIf<
958 _And<_Dep,
959 _BoolConstant<sizeof...(_Tp) == 2>,
960 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
961 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
962 >::value
963 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500964 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400965 tuple& operator=(pair<_Up1, _Up2>&& __pair)
966 _NOEXCEPT_((_And<
967 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
968 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
969 >::value))
970 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500971 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
972 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -0400973 return *this;
974 }
975
976 // EXTENSION
977 template<class _Up, size_t _Np, class = _EnableIf<
978 _And<
979 _BoolConstant<_Np == sizeof...(_Tp)>,
980 is_assignable<_Tp&, _Up const&>...
981 >::value
982 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500983 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400984 tuple& operator=(array<_Up, _Np> const& __array)
985 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
986 {
987 _VSTD::__memberwise_copy_assign(*this, __array,
988 typename __make_tuple_indices<sizeof...(_Tp)>::type());
989 return *this;
990 }
991
992 // EXTENSION
993 template<class _Up, size_t _Np, class = void, class = _EnableIf<
994 _And<
995 _BoolConstant<_Np == sizeof...(_Tp)>,
996 is_assignable<_Tp&, _Up>...
997 >::value
998 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500999 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001000 tuple& operator=(array<_Up, _Np>&& __array)
1001 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1002 {
1003 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1004 __tuple_types<_If<true, _Up, _Tp>...>(),
1005 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1006 return *this;
1007 }
1008
1009 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001010 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001011 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001012 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013};
1014
1015template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001016class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017{
1018public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001019 _LIBCPP_INLINE_VISIBILITY constexpr
1020 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001021 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001022 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001023 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001024 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001025 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001026 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001027 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001028 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001029 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001030 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001031 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001032 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001033 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001034 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035};
1036
Eric Fiselier8df4ac62017-10-04 00:04:26 +00001037#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Louis Dionne616da2a2019-08-12 18:30:31 +00001038template <class ..._Tp>
1039tuple(_Tp...) -> tuple<_Tp...>;
1040template <class _Tp1, class _Tp2>
1041tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1042template <class _Alloc, class ..._Tp>
1043tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1044template <class _Alloc, class _Tp1, class _Tp2>
1045tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1046template <class _Alloc, class ..._Tp>
1047tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001048#endif
1049
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001051inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001052typename enable_if
1053<
1054 __all<__is_swappable<_Tp>::value...>::value,
1055 void
1056>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001057swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1058 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1059 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060
1061// get
1062
1063template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001064inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001065typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001066get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001068 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001069 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070}
1071
1072template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001073inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001074const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001075get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001077 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001078 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079}
1080
Howard Hinnant22e97242010-11-17 19:52:17 +00001081template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001082inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001083typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001084get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001085{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001086 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001087 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001088 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001089}
1090
Eric Fiselier6dea8092015-12-18 00:36:55 +00001091template <size_t _Ip, class ..._Tp>
1092inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1093const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1094get(const tuple<_Tp...>&& __t) _NOEXCEPT
1095{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001096 typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001097 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001098 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001099}
1100
Marshall Clow15b02e02013-07-13 02:54:05 +00001101#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001102
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001103namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001104
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001105static constexpr size_t __not_found = -1;
1106static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001107
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001108inline _LIBCPP_INLINE_VISIBILITY
1109constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1110 return !__matches ? __res :
1111 (__res == __not_found ? __curr_i : __ambiguous);
1112}
Marshall Clow15b02e02013-07-13 02:54:05 +00001113
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001114template <size_t _Nx>
1115inline _LIBCPP_INLINE_VISIBILITY
1116constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1117 return __i == _Nx ? __not_found :
1118 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1119}
1120
1121template <class _T1, class ..._Args>
1122struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001123 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001124 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001125 static_assert(value != __not_found, "type not found in type list" );
1126 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001127};
1128
Eric Fiselier8087d302016-07-02 03:46:08 +00001129template <class _T1>
1130struct __find_exactly_one_checked<_T1> {
1131 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1132};
1133
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001134} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001135
1136template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001137struct __find_exactly_one_t
1138 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1139};
Marshall Clow15b02e02013-07-13 02:54:05 +00001140
1141template <class _T1, class... _Args>
1142inline _LIBCPP_INLINE_VISIBILITY
1143constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1144{
1145 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1146}
1147
1148template <class _T1, class... _Args>
1149inline _LIBCPP_INLINE_VISIBILITY
1150constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1151{
1152 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1153}
1154
1155template <class _T1, class... _Args>
1156inline _LIBCPP_INLINE_VISIBILITY
1157constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1158{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001159 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001160}
1161
Eric Fiselier6dea8092015-12-18 00:36:55 +00001162template <class _T1, class... _Args>
1163inline _LIBCPP_INLINE_VISIBILITY
1164constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1165{
1166 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1167}
1168
Marshall Clow15b02e02013-07-13 02:54:05 +00001169#endif
1170
Howard Hinnantc51e1022010-05-11 19:42:16 +00001171// tie
1172
1173template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001174inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001176tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001177{
1178 return tuple<_Tp&...>(__t...);
1179}
1180
1181template <class _Up>
1182struct __ignore_t
1183{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001184 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001185 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1186 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001187};
1188
Eric Fiselier24e70262017-02-06 01:25:31 +00001189namespace {
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001190 _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001191}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192
Howard Hinnantc51e1022010-05-11 19:42:16 +00001193template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001194inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001195tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196make_tuple(_Tp&&... __t)
1197{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001198 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199}
1200
Howard Hinnant3d203a32010-08-19 18:59:38 +00001201template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001202inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1203tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001204forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001205{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001206 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001207}
1208
Howard Hinnantc834c512011-11-29 18:15:50 +00001209template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210struct __tuple_equal
1211{
1212 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001213 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001214 bool operator()(const _Tp& __x, const _Up& __y)
1215 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001216 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001217 }
1218};
1219
1220template <>
1221struct __tuple_equal<0>
1222{
1223 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001224 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001225 bool operator()(const _Tp&, const _Up&)
1226 {
1227 return true;
1228 }
1229};
1230
1231template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001232inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233bool
1234operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1235{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001236 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001237 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1238}
1239
1240template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001241inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001242bool
1243operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1244{
1245 return !(__x == __y);
1246}
1247
Howard Hinnantc834c512011-11-29 18:15:50 +00001248template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001249struct __tuple_less
1250{
1251 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001252 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253 bool operator()(const _Tp& __x, const _Up& __y)
1254 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001255 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1256 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1257 return true;
1258 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1259 return false;
1260 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001261 }
1262};
1263
1264template <>
1265struct __tuple_less<0>
1266{
1267 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001268 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269 bool operator()(const _Tp&, const _Up&)
1270 {
1271 return false;
1272 }
1273};
1274
1275template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001276inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277bool
1278operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1279{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001280 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1282}
1283
1284template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001285inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286bool
1287operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1288{
1289 return __y < __x;
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{
1297 return !(__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 !(__y < __x);
1306}
1307
1308// tuple_cat
1309
Howard Hinnant6256ee72010-12-11 20:47:50 +00001310template <class _Tp, class _Up> struct __tuple_cat_type;
1311
1312template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001313struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001315 typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001316};
1317
1318template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1319struct __tuple_cat_return_1
1320{
1321};
1322
1323template <class ..._Types, class _Tuple0>
1324struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1325{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001326 typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001327 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001328 type;
1329};
1330
1331template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1332struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1333 : public __tuple_cat_return_1<
1334 typename __tuple_cat_type<
1335 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001336 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001337 >::type,
1338 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1339 _Tuple1, _Tuples...>
1340{
1341};
1342
1343template <class ..._Tuples> struct __tuple_cat_return;
1344
1345template <class _Tuple0, class ..._Tuples>
1346struct __tuple_cat_return<_Tuple0, _Tuples...>
1347 : public __tuple_cat_return_1<tuple<>,
1348 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1349 _Tuples...>
1350{
1351};
1352
1353template <>
1354struct __tuple_cat_return<>
1355{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001356 typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001357};
1358
Marshall Clow2229cee2013-07-22 16:02:19 +00001359inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001360tuple<>
1361tuple_cat()
1362{
1363 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364}
1365
Howard Hinnantc834c512011-11-29 18:15:50 +00001366template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001367struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368
Howard Hinnant21376f62010-12-12 23:04:37 +00001369template <class ..._Types, size_t ..._I0, class _Tuple0>
1370struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001372 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001373 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1374 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1375};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376
Howard Hinnant21376f62010-12-12 23:04:37 +00001377template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1378struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1379 _Tuple0, _Tuple1, _Tuples...>
1380 : public __tuple_cat_return_ref_imp<
1381 tuple<_Types..., typename __apply_cv<_Tuple0,
1382 typename tuple_element<_I0,
1383 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1384 typename __make_tuple_indices<tuple_size<typename
1385 remove_reference<_Tuple1>::type>::value>::type,
1386 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387{
Howard Hinnant21376f62010-12-12 23:04:37 +00001388};
1389
1390template <class _Tuple0, class ..._Tuples>
1391struct __tuple_cat_return_ref
1392 : public __tuple_cat_return_ref_imp<tuple<>,
1393 typename __make_tuple_indices<
1394 tuple_size<typename remove_reference<_Tuple0>::type>::value
1395 >::type, _Tuple0, _Tuples...>
1396{
1397};
1398
1399template <class _Types, class _I0, class _J0>
1400struct __tuple_cat;
1401
1402template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001403struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001404{
1405 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001406 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001407 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1408 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1409 {
David Blaikie699a5e22019-10-28 18:03:59 -07001410 return _VSTD::forward_as_tuple(
1411 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1412 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001413 }
1414
1415 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001416 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001417 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1418 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1419 {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001420 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
1421 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001422 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001423 tuple<_Types...,
1424 typename __apply_cv<_Tuple0, typename tuple_element<
1425 _J0, _T0>::type>::type&&...>,
1426 typename __make_tuple_indices<sizeof...(_Types) +
1427 tuple_size<_T0>::value>::type,
1428 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1429 _VSTD::forward_as_tuple(
1430 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1431 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1432 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001433 }
1434};
1435
1436template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001437inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001438typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1439tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1440{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001441 typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001442 return __tuple_cat<tuple<>, __tuple_indices<>,
1443 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001444 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1445 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446}
1447
1448template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001449struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450 : true_type {};
1451
Howard Hinnantc51e1022010-05-11 19:42:16 +00001452template <class _T1, class _T2>
1453template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001454inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001455pair<_T1, _T2>::pair(piecewise_construct_t,
1456 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1457 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001458 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1459 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460{
1461}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462
Eric Fiselier8e892c52016-07-18 00:35:56 +00001463#if _LIBCPP_STD_VER > 14
1464template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001465_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001466
1467#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1468
1469template <class _Fn, class _Tuple, size_t ..._Id>
1470inline _LIBCPP_INLINE_VISIBILITY
1471constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1472 __tuple_indices<_Id...>)
1473_LIBCPP_NOEXCEPT_RETURN(
1474 _VSTD::__invoke_constexpr(
1475 _VSTD::forward<_Fn>(__f),
1476 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1477)
1478
1479template <class _Fn, class _Tuple>
1480inline _LIBCPP_INLINE_VISIBILITY
1481constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1482_LIBCPP_NOEXCEPT_RETURN(
1483 _VSTD::__apply_tuple_impl(
1484 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001485 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001486)
1487
1488template <class _Tp, class _Tuple, size_t... _Idx>
1489inline _LIBCPP_INLINE_VISIBILITY
1490constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1491_LIBCPP_NOEXCEPT_RETURN(
1492 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1493)
1494
1495template <class _Tp, class _Tuple>
1496inline _LIBCPP_INLINE_VISIBILITY
1497constexpr _Tp make_from_tuple(_Tuple&& __t)
1498_LIBCPP_NOEXCEPT_RETURN(
1499 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001500 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001501)
1502
1503#undef _LIBCPP_NOEXCEPT_RETURN
1504
1505#endif // _LIBCPP_STD_VER > 14
1506
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001507#endif // !defined(_LIBCPP_CXX03_LANG)
1508
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509_LIBCPP_END_NAMESPACE_STD
1510
1511#endif // _LIBCPP_TUPLE