blob: 93b6e6049895853b378f3abf31d6e1182e8140a1 [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>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000153#include <__functional/unwrap_ref.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400154#include <__functional_base>
155#include <__memory/allocator_arg_t.h>
156#include <__memory/uses_allocator.h>
157#include <__tuple>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000158#include <__utility/forward.h>
159#include <__utility/move.h>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400160#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161#include <cstddef>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000162#include <type_traits>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000163#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000164#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000166#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000168#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169
170_LIBCPP_BEGIN_NAMESPACE_STD
171
Eric Fiselierffe4aba2017-04-19 01:23:39 +0000172#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173
Marshall Clowf50d66f2014-03-03 06:18:11 +0000174
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175// __tuple_leaf
176
Eric Fiselierf7394302015-06-13 07:08:02 +0000177template <size_t _Ip, class _Hp,
178 bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +0000179 >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180class __tuple_leaf;
181
182template <size_t _Ip, class _Hp, bool _Ep>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500183inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000185 _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186{
187 swap(__x.get(), __y.get());
188}
189
190template <size_t _Ip, class _Hp, bool>
191class __tuple_leaf
192{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000193 _Hp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194
Eric Fiselierca8bba12016-07-20 02:57:39 +0000195 template <class _Tp>
196 static constexpr bool __can_bind_reference() {
Eric Fiselier869187d2018-01-24 22:14:01 +0000197#if __has_keyword(__reference_binds_to_temporary)
198 return !__reference_binds_to_temporary(_Hp, _Tp);
Eric Fiselier81c32cb2018-01-24 23:10:02 +0000199#else
200 return true;
Eric Fiselier869187d2018-01-24 22:14:01 +0000201#endif
Eric Fiselierca8bba12016-07-20 02:57:39 +0000202 }
203
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500204 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205 __tuple_leaf& operator=(const __tuple_leaf&);
206public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500207 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000208 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000209 {static_assert(!is_reference<_Hp>::value,
210 "Attempted to default construct a reference element in a tuple");}
211
212 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500213 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000214 __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000215 : __value_()
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216 {static_assert(!is_reference<_Hp>::value,
217 "Attempted to default construct a reference element in a tuple");}
218
219 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500220 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000222 : __value_(allocator_arg_t(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000223 {static_assert(!is_reference<_Hp>::value,
224 "Attempted to default construct a reference element in a tuple");}
225
226 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500227 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000229 : __value_(__a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000230 {static_assert(!is_reference<_Hp>::value,
231 "Attempted to default construct a reference element in a tuple");}
232
Howard Hinnant693fc212010-09-27 17:54:17 +0000233 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400234 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000235 _And<
236 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
237 is_constructible<_Hp, _Tp>
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000238 >::value
Eric Fiselier3906a132019-06-23 20:28:29 +0000239 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000240 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000241 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000242 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000243 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000244 {static_assert(__can_bind_reference<_Tp&&>(),
245 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246
247 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500248 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000250 : __value_(_VSTD::forward<_Tp>(__t))
Eric Fiselier869187d2018-01-24 22:14:01 +0000251 {static_assert(__can_bind_reference<_Tp&&>(),
252 "Attempted construction of reference element binds to a temporary whose lifetime has ended");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253
254 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500255 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000257 : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
Eric Fiselierca8bba12016-07-20 02:57:39 +0000258 {static_assert(!is_reference<_Hp>::value,
259 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260
261 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500262 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000264 : __value_(_VSTD::forward<_Tp>(__t), __a)
Eric Fiselierca8bba12016-07-20 02:57:39 +0000265 {static_assert(!is_reference<_Hp>::value,
266 "Attempted to uses-allocator construct a reference element in a tuple");}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000267
Marshall Clow47fcee52014-04-21 23:48:09 +0000268 __tuple_leaf(const __tuple_leaf& __t) = default;
269 __tuple_leaf(__tuple_leaf&& __t) = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500271 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000272 int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000274 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 return 0;
276 }
277
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000278 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
279 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280};
281
282template <size_t _Ip, class _Hp>
283class __tuple_leaf<_Ip, _Hp, true>
284 : private _Hp
285{
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500286 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287 __tuple_leaf& operator=(const __tuple_leaf&);
288public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500289 _LIBCPP_INLINE_VISIBILITY constexpr __tuple_leaf()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000290 _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291
292 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500293 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294 __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
295
296 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500297 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000298 __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
299 : _Hp(allocator_arg_t(), __a) {}
300
301 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500302 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303 __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
304 : _Hp(__a) {}
305
Howard Hinnant693fc212010-09-27 17:54:17 +0000306 template <class _Tp,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400307 class = __enable_if_t<
Eric Fiselier3906a132019-06-23 20:28:29 +0000308 _And<
309 _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
310 is_constructible<_Hp, _Tp>
311 >::value
312 >
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000313 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000314 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000315 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000316 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317
318 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500319 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000321 : _Hp(_VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000322
323 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500324 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000326 : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327
328 template <class _Tp, class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500329 _LIBCPP_INLINE_VISIBILITY constexpr
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000331 : _Hp(_VSTD::forward<_Tp>(__t), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332
Eric Fiselier42fa85e2014-07-24 18:48:34 +0000333 __tuple_leaf(__tuple_leaf const &) = default;
334 __tuple_leaf(__tuple_leaf &&) = default;
335
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500336 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant89ef1212011-05-27 19:08:18 +0000337 int
338 swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000340 _VSTD::swap(*this, __t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341 return 0;
342 }
343
Marshall Clow2229cee2013-07-22 16:02:19 +0000344 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
345 _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 +0000346};
347
Howard Hinnant1c265cd2010-09-23 18:58:28 +0000348template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500349_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000350void __swallow(_Tp&&...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351
Marshall Clowc470eae2014-10-15 10:33:02 +0000352template <class _Tp>
353struct __all_default_constructible;
Howard Hinnant89ef1212011-05-27 19:08:18 +0000354
Marshall Clowc470eae2014-10-15 10:33:02 +0000355template <class ..._Tp>
356struct __all_default_constructible<__tuple_types<_Tp...>>
357 : __all<is_default_constructible<_Tp>::value...>
358{ };
Howard Hinnant89ef1212011-05-27 19:08:18 +0000359
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360// __tuple_impl
361
362template<class _Indx, class ..._Tp> struct __tuple_impl;
363
364template<size_t ..._Indx, class ..._Tp>
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000365struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 : public __tuple_leaf<_Indx, _Tp>...
367{
Howard Hinnant38469632012-07-06 20:39:45 +0000368 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500369 constexpr __tuple_impl()
Howard Hinnantaabb4202012-07-06 20:50:27 +0000370 _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
Howard Hinnant38469632012-07-06 20:39:45 +0000371
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372 template <size_t ..._Uf, class ..._Tf,
373 size_t ..._Ul, class ..._Tl, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +0000374 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 explicit
376 __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
377 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
Howard Hinnant62751642012-07-06 21:53:48 +0000378 _Up&&... __u)
379 _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
380 __all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000381 __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382 __tuple_leaf<_Ul, _Tl>()...
383 {}
384
385 template <class _Alloc, size_t ..._Uf, class ..._Tf,
386 size_t ..._Ul, class ..._Tl, class ..._Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500387 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000388 explicit
389 __tuple_impl(allocator_arg_t, const _Alloc& __a,
390 __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
391 __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
392 _Up&&... __u) :
393 __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000394 _VSTD::forward<_Up>(__u))...,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
396 {}
397
398 template <class _Tuple,
399 class = typename enable_if
400 <
Howard Hinnant6da16b82013-04-14 00:01:13 +0000401 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 >::type
403 >
Marshall Clow2229cee2013-07-22 16:02:19 +0000404 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant62751642012-07-06 21:53:48 +0000405 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
406 typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000407 : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
408 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 {}
410
411 template <class _Alloc, class _Tuple,
412 class = typename enable_if
413 <
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000414 __tuple_constructible<_Tuple, tuple<_Tp...> >::value
Howard Hinnantc51e1022010-05-11 19:42:16 +0000415 >::type
416 >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500417 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000418 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
419 : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000420 typename __make_tuple_types<_Tuple>::type>::type>(), __a,
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000421 _VSTD::forward<typename tuple_element<_Indx,
422 typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 {}
424
Howard Hinnant0d032d12013-11-06 17:45:43 +0000425 __tuple_impl(const __tuple_impl&) = default;
426 __tuple_impl(__tuple_impl&&) = default;
427
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500428 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429 void swap(__tuple_impl& __t)
Howard Hinnant89ef1212011-05-27 19:08:18 +0000430 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400432 _VSTD::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433 }
434};
435
Louis Dionne6c0d5342018-07-31 11:56:20 -0400436template<class _Dest, class _Source, 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_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) {
439 _VSTD::__swallow(((_VSTD::get<_Np>(__dest) = _VSTD::get<_Np>(__source)), void(), 0)...);
440}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000441
Louis Dionne6c0d5342018-07-31 11:56:20 -0400442template<class _Dest, class _Source, class ..._Up, size_t ..._Np>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500443_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne6c0d5342018-07-31 11:56:20 -0400444void __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) {
445 _VSTD::__swallow(((
Louis Dionne3b8af4d2021-02-24 14:53:21 -0500446 _VSTD::get<_Np>(__dest) = _VSTD::forward<_Up>(_VSTD::get<_Np>(__source))
Louis Dionne6c0d5342018-07-31 11:56:20 -0400447 ), void(), 0)...);
448}
Eric Fiselier264d04a2016-04-15 18:05:59 +0000449
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450template <class ..._Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000451class _LIBCPP_TEMPLATE_VIS tuple
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452{
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000453 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000454
Eric Fiselier3e0d4372017-06-01 02:14:21 +0000455 _BaseT __base_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456
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 typename tuple_element<_Jp, tuple<_Up...> >::type& get(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 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
Marshall Clow0abb1042013-07-17 18:25:36 +0000461 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant28b24882011-12-01 20:21:04 +0000462 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
Eric Fiselier6dea8092015-12-18 00:36:55 +0000463 template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
464 const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000465public:
Louis Dionne574e2e32021-02-10 16:19:50 -0500466 // [tuple.cnstr]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467
Louis Dionne574e2e32021-02-10 16:19:50 -0500468 // tuple() constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400469 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500470 _And<
471 _IsImpDefault<_Tp>... // explicit check
472 >::value
473 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400474 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000475 tuple()
Louis Dionne574e2e32021-02-10 16:19:50 -0500476 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
477 { }
Louis Dionnea7a2beb2019-09-26 14:51:10 +0000478
Louis Dionne574e2e32021-02-10 16:19:50 -0500479 template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400480 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500481 _And<
482 _IsDefault<_Tp>...,
483 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
484 >::value
485 , int> = 0>
486 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
487 explicit tuple()
488 _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value)
489 { }
Howard Hinnant38469632012-07-06 20:39:45 +0000490
Louis Dionne9ce598d2021-09-08 09:14:43 -0400491 template <class _Alloc, template<class...> class _IsImpDefault = __is_implicitly_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500492 _And<
493 _IsImpDefault<_Tp>... // explicit check
494 >::value
495 , int> = 0>
496 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
497 tuple(allocator_arg_t, _Alloc const& __a)
498 : __base_(allocator_arg_t(), __a,
499 __tuple_indices<>(), __tuple_types<>(),
500 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
501 __tuple_types<_Tp...>()) {}
502
503 template <class _Alloc,
504 template<class...> class _IsImpDefault = __is_implicitly_default_constructible,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400505 template<class...> class _IsDefault = is_default_constructible, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500506 _And<
507 _IsDefault<_Tp>...,
508 _Not<_Lazy<_And, _IsImpDefault<_Tp>...> > // explicit check
509 >::value
510 , int> = 0>
511 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
512 explicit tuple(allocator_arg_t, _Alloc const& __a)
513 : __base_(allocator_arg_t(), __a,
514 __tuple_indices<>(), __tuple_types<>(),
515 typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
516 __tuple_types<_Tp...>()) {}
517
518 // tuple(const T&...) constructors (including allocator_arg_t variants)
Louis Dionne9ce598d2021-09-08 09:14:43 -0400519 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500520 _And<
521 _BoolConstant<sizeof...(_Tp) >= 1>,
522 is_copy_constructible<_Tp>...,
523 is_convertible<const _Tp&, _Tp>... // explicit check
524 >::value
525 , int> = 0>
526 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
527 tuple(const _Tp& ... __t)
528 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
529 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
530 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
531 typename __make_tuple_indices<0>::type(),
532 typename __make_tuple_types<tuple, 0>::type(),
533 __t...
534 ) {}
535
Louis Dionne9ce598d2021-09-08 09:14:43 -0400536 template <template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500537 _And<
538 _BoolConstant<sizeof...(_Tp) >= 1>,
539 is_copy_constructible<_Tp>...,
540 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
541 >::value
542 , int> = 0>
543 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
544 explicit tuple(const _Tp& ... __t)
545 _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value)
546 : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
547 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
548 typename __make_tuple_indices<0>::type(),
549 typename __make_tuple_types<tuple, 0>::type(),
550 __t...
551 ) {}
552
Louis Dionne9ce598d2021-09-08 09:14:43 -0400553 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500554 _And<
555 _BoolConstant<sizeof...(_Tp) >= 1>,
556 is_copy_constructible<_Tp>...,
557 is_convertible<const _Tp&, _Tp>... // explicit check
558 >::value
559 , int> = 0>
560 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
561 tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
562 : __base_(allocator_arg_t(), __a,
563 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
564 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
565 typename __make_tuple_indices<0>::type(),
566 typename __make_tuple_types<tuple, 0>::type(),
567 __t...
568 ) {}
569
Louis Dionne9ce598d2021-09-08 09:14:43 -0400570 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500571 _And<
572 _BoolConstant<sizeof...(_Tp) >= 1>,
573 is_copy_constructible<_Tp>...,
574 _Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> > // explicit check
575 >::value
576 , int> = 0>
577 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
578 explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
579 : __base_(allocator_arg_t(), __a,
580 typename __make_tuple_indices<sizeof...(_Tp)>::type(),
581 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
582 typename __make_tuple_indices<0>::type(),
583 typename __make_tuple_types<tuple, 0>::type(),
584 __t...
585 ) {}
586
587 // tuple(U&& ...) constructors (including allocator_arg_t variants)
588 template <class ..._Up> struct _IsThisTuple : false_type { };
589 template <class _Up> struct _IsThisTuple<_Up> : is_same<__uncvref_t<_Up>, tuple> { };
590
591 template <class ..._Up>
592 struct _EnableUTypesCtor : _And<
593 _BoolConstant<sizeof...(_Tp) >= 1>,
594 _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors
595 is_constructible<_Tp, _Up>...
596 > { };
597
Louis Dionne9ce598d2021-09-08 09:14:43 -0400598 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500599 _And<
600 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
601 _EnableUTypesCtor<_Up...>,
602 is_convertible<_Up, _Tp>... // explicit check
603 >::value
604 , int> = 0>
605 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
606 tuple(_Up&&... __u)
607 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
608 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
609 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
610 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
611 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
612 _VSTD::forward<_Up>(__u)...) {}
613
Louis Dionne9ce598d2021-09-08 09:14:43 -0400614 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500615 _And<
616 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
617 _EnableUTypesCtor<_Up...>,
618 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
619 >::value
620 , int> = 0>
621 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
622 explicit tuple(_Up&&... __u)
623 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
624 : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
625 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
626 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
627 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
628 _VSTD::forward<_Up>(__u)...) {}
629
Louis Dionne9ce598d2021-09-08 09:14:43 -0400630 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500631 _And<
632 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
633 _EnableUTypesCtor<_Up...>,
634 is_convertible<_Up, _Tp>... // explicit check
635 >::value
636 , int> = 0>
637 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
638 tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
639 : __base_(allocator_arg_t(), __a,
640 typename __make_tuple_indices<sizeof...(_Up)>::type(),
641 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
642 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
643 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
644 _VSTD::forward<_Up>(__u)...) {}
645
Louis Dionne9ce598d2021-09-08 09:14:43 -0400646 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500647 _And<
648 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
649 _EnableUTypesCtor<_Up...>,
650 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
651 >::value
652 , int> = 0>
653 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
654 explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
655 : __base_(allocator_arg_t(), __a,
656 typename __make_tuple_indices<sizeof...(_Up)>::type(),
657 typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
658 typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
659 typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
660 _VSTD::forward<_Up>(__u)...) {}
661
662 // Copy and move constructors (including the allocator_arg_t variants)
663 tuple(const tuple&) = default;
Eric Fiselier737a16d2016-07-25 02:36:42 +0000664 tuple(tuple&&) = default;
665
Louis Dionne9ce598d2021-09-08 09:14:43 -0400666 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500667 _And<is_copy_constructible<_Tp>...>::value
668 , int> = 0>
669 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t)
670 : __base_(allocator_arg_t(), __alloc, __t)
671 { }
672
Louis Dionne9ce598d2021-09-08 09:14:43 -0400673 template <class _Alloc, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500674 _And<is_move_constructible<_Tp>...>::value
675 , int> = 0>
676 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t)
677 : __base_(allocator_arg_t(), __alloc, _VSTD::move(__t))
678 { }
679
680 // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants)
681 template <class ..._Up>
682 struct _EnableCopyFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400683 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
684 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500685 _BoolConstant<sizeof...(_Tp) != 1>,
686 // _Tp and _Up are 1-element packs - the pack expansions look
687 // weird to avoid tripping up the type traits in degenerate cases
688 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500689 _Not<is_convertible<const tuple<_Up>&, _Tp> >...,
690 _Not<is_constructible<_Tp, const tuple<_Up>&> >...
691 >
692 >,
693 is_constructible<_Tp, const _Up&>...
694 > { };
695
Louis Dionne9ce598d2021-09-08 09:14:43 -0400696 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500697 _And<
698 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
699 _EnableCopyFromOtherTuple<_Up...>,
700 is_convertible<const _Up&, _Tp>... // explicit check
701 >::value
702 , int> = 0>
703 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
704 tuple(const tuple<_Up...>& __t)
705 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
706 : __base_(__t)
707 { }
708
Louis Dionne9ce598d2021-09-08 09:14:43 -0400709 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500710 _And<
711 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
712 _EnableCopyFromOtherTuple<_Up...>,
713 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
714 >::value
715 , int> = 0>
716 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
717 explicit tuple(const tuple<_Up...>& __t)
718 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value))
719 : __base_(__t)
720 { }
721
Louis Dionne9ce598d2021-09-08 09:14:43 -0400722 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500723 _And<
724 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
725 _EnableCopyFromOtherTuple<_Up...>,
726 is_convertible<const _Up&, _Tp>... // explicit check
727 >::value
728 , int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500729 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne574e2e32021-02-10 16:19:50 -0500730 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
731 : __base_(allocator_arg_t(), __a, __t)
732 { }
Eric Fiselierc170df52016-04-15 03:29:40 +0000733
Louis Dionne9ce598d2021-09-08 09:14:43 -0400734 template <class ..._Up, class _Alloc, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500735 _And<
736 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
737 _EnableCopyFromOtherTuple<_Up...>,
738 _Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> > // explicit check
739 >::value
740 , int> = 0>
741 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
742 explicit tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
743 : __base_(allocator_arg_t(), __a, __t)
744 { }
Louis Dionne668a50c2019-09-27 15:06:52 +0000745
Louis Dionne574e2e32021-02-10 16:19:50 -0500746 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
747 template <class ..._Up>
748 struct _EnableMoveFromOtherTuple : _And<
Louis Dionnedb7e65d2021-05-03 12:21:13 -0400749 _Not<is_same<tuple<_Tp...>, tuple<_Up...> > >,
750 _Lazy<_Or,
Louis Dionne574e2e32021-02-10 16:19:50 -0500751 _BoolConstant<sizeof...(_Tp) != 1>,
752 // _Tp and _Up are 1-element packs - the pack expansions look
753 // weird to avoid tripping up the type traits in degenerate cases
754 _Lazy<_And,
Louis Dionne574e2e32021-02-10 16:19:50 -0500755 _Not<is_convertible<tuple<_Up>, _Tp> >...,
756 _Not<is_constructible<_Tp, tuple<_Up> > >...
757 >
758 >,
759 is_constructible<_Tp, _Up>...
760 > { };
761
Louis Dionne9ce598d2021-09-08 09:14:43 -0400762 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500763 _And<
764 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
765 _EnableMoveFromOtherTuple<_Up...>,
766 is_convertible<_Up, _Tp>... // explicit check
767 >::value
768 , int> = 0>
Marshall Clow2229cee2013-07-22 16:02:19 +0000769 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500770 tuple(tuple<_Up...>&& __t)
771 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
772 : __base_(_VSTD::move(__t))
773 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774
Louis Dionne9ce598d2021-09-08 09:14:43 -0400775 template <class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500776 _And<
777 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
778 _EnableMoveFromOtherTuple<_Up...>,
779 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
780 >::value
781 , int> = 0>
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000782 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500783 explicit tuple(tuple<_Up...>&& __t)
784 _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value))
785 : __base_(_VSTD::move(__t))
786 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000787
Louis Dionne9ce598d2021-09-08 09:14:43 -0400788 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500789 _And<
790 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
791 _EnableMoveFromOtherTuple<_Up...>,
792 is_convertible<_Up, _Tp>... // explicit check
793 >::value
794 , int> = 0>
795 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
796 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
797 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
798 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799
Louis Dionne9ce598d2021-09-08 09:14:43 -0400800 template <class _Alloc, class ..._Up, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500801 _And<
802 _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>,
803 _EnableMoveFromOtherTuple<_Up...>,
804 _Not<_Lazy<_And, is_convertible<_Up, _Tp>...> > // explicit check
805 >::value
806 , int> = 0>
807 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
808 explicit tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
809 : __base_(allocator_arg_t(), __a, _VSTD::move(__t))
810 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000811
Louis Dionne574e2e32021-02-10 16:19:50 -0500812 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
813 template <class _Up1, class _Up2, class ..._DependentTp>
814 struct _EnableImplicitCopyFromPair : _And<
815 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
816 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
817 is_convertible<const _Up1&, _FirstType<_DependentTp...> >, // explicit check
818 is_convertible<const _Up2&, _SecondType<_DependentTp...> >
819 > { };
Howard Hinnant65704d02012-04-01 23:10:42 +0000820
Louis Dionne574e2e32021-02-10 16:19:50 -0500821 template <class _Up1, class _Up2, class ..._DependentTp>
822 struct _EnableExplicitCopyFromPair : _And<
823 is_constructible<_FirstType<_DependentTp...>, const _Up1&>,
824 is_constructible<_SecondType<_DependentTp...>, const _Up2&>,
825 _Not<is_convertible<const _Up1&, _FirstType<_DependentTp...> > >, // explicit check
826 _Not<is_convertible<const _Up2&, _SecondType<_DependentTp...> > >
827 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828
Louis Dionne9ce598d2021-09-08 09:14:43 -0400829 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500830 _And<
831 _BoolConstant<sizeof...(_Tp) == 2>,
832 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
833 >::value
834 , int> = 0>
835 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
836 tuple(const pair<_Up1, _Up2>& __p)
837 _NOEXCEPT_((_And<
838 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
839 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
840 >::value))
841 : __base_(__p)
842 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843
Louis Dionne9ce598d2021-09-08 09:14:43 -0400844 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500845 _And<
846 _BoolConstant<sizeof...(_Tp) == 2>,
847 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
848 >::value
849 , int> = 0>
850 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
851 explicit tuple(const pair<_Up1, _Up2>& __p)
852 _NOEXCEPT_((_And<
853 is_nothrow_constructible<_FirstType<_Tp...>, const _Up1&>,
854 is_nothrow_constructible<_SecondType<_Tp...>, const _Up2&>
855 >::value))
856 : __base_(__p)
857 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000858
Louis Dionne9ce598d2021-09-08 09:14:43 -0400859 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500860 _And<
861 _BoolConstant<sizeof...(_Tp) == 2>,
862 _EnableImplicitCopyFromPair<_Up1, _Up2, _Tp...>
863 >::value
864 , int> = 0>
865 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
866 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
867 : __base_(allocator_arg_t(), __a, __p)
868 { }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869
Louis Dionne9ce598d2021-09-08 09:14:43 -0400870 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500871 _And<
872 _BoolConstant<sizeof...(_Tp) == 2>,
873 _EnableExplicitCopyFromPair<_Up1, _Up2, _Tp...>
874 >::value
875 , int> = 0>
876 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
877 explicit tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
878 : __base_(allocator_arg_t(), __a, __p)
879 { }
Howard Hinnant65704d02012-04-01 23:10:42 +0000880
Louis Dionne574e2e32021-02-10 16:19:50 -0500881 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
882 template <class _Up1, class _Up2, class ..._DependentTp>
883 struct _EnableImplicitMoveFromPair : _And<
884 is_constructible<_FirstType<_DependentTp...>, _Up1>,
885 is_constructible<_SecondType<_DependentTp...>, _Up2>,
886 is_convertible<_Up1, _FirstType<_DependentTp...> >, // explicit check
887 is_convertible<_Up2, _SecondType<_DependentTp...> >
888 > { };
Eric Fiselierec5a2102019-07-12 23:01:48 +0000889
Louis Dionne574e2e32021-02-10 16:19:50 -0500890 template <class _Up1, class _Up2, class ..._DependentTp>
891 struct _EnableExplicitMoveFromPair : _And<
892 is_constructible<_FirstType<_DependentTp...>, _Up1>,
893 is_constructible<_SecondType<_DependentTp...>, _Up2>,
894 _Not<is_convertible<_Up1, _FirstType<_DependentTp...> > >, // explicit check
895 _Not<is_convertible<_Up2, _SecondType<_DependentTp...> > >
896 > { };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897
Louis Dionne9ce598d2021-09-08 09:14:43 -0400898 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500899 _And<
900 _BoolConstant<sizeof...(_Tp) == 2>,
901 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
902 >::value
903 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400904 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500905 tuple(pair<_Up1, _Up2>&& __p)
906 _NOEXCEPT_((_And<
907 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
908 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
909 >::value))
910 : __base_(_VSTD::move(__p))
911 { }
912
Louis Dionne9ce598d2021-09-08 09:14:43 -0400913 template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500914 _And<
915 _BoolConstant<sizeof...(_Tp) == 2>,
916 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
917 >::value
918 , int> = 0>
Louis Dionne58bca852021-04-30 15:52:26 -0400919 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionne574e2e32021-02-10 16:19:50 -0500920 explicit tuple(pair<_Up1, _Up2>&& __p)
921 _NOEXCEPT_((_And<
922 is_nothrow_constructible<_FirstType<_Tp...>, _Up1>,
923 is_nothrow_constructible<_SecondType<_Tp...>, _Up2>
924 >::value))
925 : __base_(_VSTD::move(__p))
926 { }
927
Louis Dionne9ce598d2021-09-08 09:14:43 -0400928 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500929 _And<
930 _BoolConstant<sizeof...(_Tp) == 2>,
931 _EnableImplicitMoveFromPair<_Up1, _Up2, _Tp...>
932 >::value
933 , int> = 0>
934 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
935 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
936 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
937 { }
938
Louis Dionne9ce598d2021-09-08 09:14:43 -0400939 template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t<
Louis Dionne574e2e32021-02-10 16:19:50 -0500940 _And<
941 _BoolConstant<sizeof...(_Tp) == 2>,
942 _EnableExplicitMoveFromPair<_Up1, _Up2, _Tp...>
943 >::value
944 , int> = 0>
945 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
946 explicit tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
947 : __base_(allocator_arg_t(), __a, _VSTD::move(__p))
948 { }
Eric Fiselier8e6a5f02016-04-19 01:19:25 +0000949
Louis Dionne6c0d5342018-07-31 11:56:20 -0400950 // [tuple.assign]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500951 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400952 tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
953 _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000954 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400955 _VSTD::__memberwise_copy_assign(*this, __tuple,
956 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000957 return *this;
958 }
959
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500960 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400961 tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
962 _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value))
Eric Fiselier737a16d2016-07-25 02:36:42 +0000963 {
Louis Dionne6c0d5342018-07-31 11:56:20 -0400964 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
965 __tuple_types<_Tp...>(),
966 typename __make_tuple_indices<sizeof...(_Tp)>::type());
Eric Fiselier737a16d2016-07-25 02:36:42 +0000967 return *this;
968 }
969
Louis Dionne9ce598d2021-09-08 09:14:43 -0400970 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -0400971 _And<
972 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
973 is_assignable<_Tp&, _Up const&>...
974 >::value
975 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500976 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400977 tuple& operator=(tuple<_Up...> const& __tuple)
978 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
979 {
980 _VSTD::__memberwise_copy_assign(*this, __tuple,
981 typename __make_tuple_indices<sizeof...(_Tp)>::type());
982 return *this;
983 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984
Louis Dionne9ce598d2021-09-08 09:14:43 -0400985 template<class... _Up, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -0400986 _And<
987 _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>,
988 is_assignable<_Tp&, _Up>...
989 >::value
990 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500991 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -0400992 tuple& operator=(tuple<_Up...>&& __tuple)
993 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
994 {
995 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__tuple),
996 __tuple_types<_Up...>(),
997 typename __make_tuple_indices<sizeof...(_Tp)>::type());
998 return *this;
999 }
1000
Louis Dionne9ce598d2021-09-08 09:14:43 -04001001 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001002 _And<_Dep,
1003 _BoolConstant<sizeof...(_Tp) == 2>,
1004 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1 const&>,
1005 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2 const&>
1006 >::value
1007 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001008 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001009 tuple& operator=(pair<_Up1, _Up2> const& __pair)
1010 _NOEXCEPT_((_And<
1011 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1 const&>,
1012 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2 const&>
1013 >::value))
1014 {
1015 _VSTD::get<0>(*this) = __pair.first;
1016 _VSTD::get<1>(*this) = __pair.second;
1017 return *this;
1018 }
1019
Louis Dionne9ce598d2021-09-08 09:14:43 -04001020 template<class _Up1, class _Up2, class _Dep = true_type, __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001021 _And<_Dep,
1022 _BoolConstant<sizeof...(_Tp) == 2>,
1023 is_assignable<_FirstType<_Tp..., _Dep>&, _Up1>,
1024 is_assignable<_SecondType<_Tp..., _Dep>&, _Up2>
1025 >::value
1026 ,int> = 0>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001027 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001028 tuple& operator=(pair<_Up1, _Up2>&& __pair)
1029 _NOEXCEPT_((_And<
1030 is_nothrow_assignable<_FirstType<_Tp...>&, _Up1>,
1031 is_nothrow_assignable<_SecondType<_Tp...>&, _Up2>
1032 >::value))
1033 {
Louis Dionne3b8af4d2021-02-24 14:53:21 -05001034 _VSTD::get<0>(*this) = _VSTD::forward<_Up1>(__pair.first);
1035 _VSTD::get<1>(*this) = _VSTD::forward<_Up2>(__pair.second);
Louis Dionne6c0d5342018-07-31 11:56:20 -04001036 return *this;
1037 }
1038
1039 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001040 template<class _Up, size_t _Np, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001041 _And<
1042 _BoolConstant<_Np == sizeof...(_Tp)>,
1043 is_assignable<_Tp&, _Up const&>...
1044 >::value
1045 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001046 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001047 tuple& operator=(array<_Up, _Np> const& __array)
1048 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value))
1049 {
1050 _VSTD::__memberwise_copy_assign(*this, __array,
1051 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1052 return *this;
1053 }
1054
1055 // EXTENSION
Louis Dionne9ce598d2021-09-08 09:14:43 -04001056 template<class _Up, size_t _Np, class = void, class = __enable_if_t<
Louis Dionne6c0d5342018-07-31 11:56:20 -04001057 _And<
1058 _BoolConstant<_Np == sizeof...(_Tp)>,
1059 is_assignable<_Tp&, _Up>...
1060 >::value
1061 > >
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001062 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne6c0d5342018-07-31 11:56:20 -04001063 tuple& operator=(array<_Up, _Np>&& __array)
1064 _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value))
1065 {
1066 _VSTD::__memberwise_forward_assign(*this, _VSTD::move(__array),
1067 __tuple_types<_If<true, _Up, _Tp>...>(),
1068 typename __make_tuple_indices<sizeof...(_Tp)>::type());
1069 return *this;
1070 }
1071
1072 // [tuple.swap]
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001073 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001074 void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001075 {__base_.swap(__t.__base_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076};
1077
1078template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001079class _LIBCPP_TEMPLATE_VIS tuple<>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080{
1081public:
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001082 _LIBCPP_INLINE_VISIBILITY constexpr
1083 tuple() _NOEXCEPT = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001085 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001086 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087 template <class _Alloc>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001088 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001089 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001090 template <class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001091 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001092 tuple(array<_Up, 0>) _NOEXCEPT {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001093 template <class _Alloc, class _Up>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant62751642012-07-06 21:53:48 +00001095 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001096 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant89ef1212011-05-27 19:08:18 +00001097 void swap(tuple&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098};
1099
Louis Dionned59f8a52021-08-17 11:59:07 -04001100#if _LIBCPP_STD_VER >= 17
Louis Dionne616da2a2019-08-12 18:30:31 +00001101template <class ..._Tp>
1102tuple(_Tp...) -> tuple<_Tp...>;
1103template <class _Tp1, class _Tp2>
1104tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1105template <class _Alloc, class ..._Tp>
1106tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
1107template <class _Alloc, class _Tp1, class _Tp2>
1108tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
1109template <class _Alloc, class ..._Tp>
1110tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
Eric Fiselier9a5075c2017-06-08 07:18:17 +00001111#endif
1112
Howard Hinnantc51e1022010-05-11 19:42:16 +00001113template <class ..._Tp>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001114inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant44267242011-06-01 19:59:32 +00001115typename enable_if
1116<
1117 __all<__is_swappable<_Tp>::value...>::value,
1118 void
1119>::type
Howard Hinnant89ef1212011-05-27 19:08:18 +00001120swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1121 _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
1122 {__t.swap(__u);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123
1124// get
1125
1126template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001127inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001128typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001129get(tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001131 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001132 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001133}
1134
1135template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001136inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001137const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnant28b24882011-12-01 20:21:04 +00001138get(const tuple<_Tp...>& __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001139{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001140 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001141 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142}
1143
Howard Hinnant22e97242010-11-17 19:52:17 +00001144template <size_t _Ip, class ..._Tp>
Marshall Clow0abb1042013-07-17 18:25:36 +00001145inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001146typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnant28b24882011-12-01 20:21:04 +00001147get(tuple<_Tp...>&& __t) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +00001148{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001149 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Howard Hinnantb574f9a2011-01-25 16:31:30 +00001150 return static_cast<type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001151 static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Howard Hinnant22e97242010-11-17 19:52:17 +00001152}
1153
Eric Fiselier6dea8092015-12-18 00:36:55 +00001154template <size_t _Ip, class ..._Tp>
1155inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1156const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
1157get(const tuple<_Tp...>&& __t) _NOEXCEPT
1158{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001159 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
Eric Fiselier6dea8092015-12-18 00:36:55 +00001160 return static_cast<const type&&>(
Eric Fiselier3e0d4372017-06-01 02:14:21 +00001161 static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
Eric Fiselier6dea8092015-12-18 00:36:55 +00001162}
1163
Marshall Clow15b02e02013-07-13 02:54:05 +00001164#if _LIBCPP_STD_VER > 11
Marshall Clow15b02e02013-07-13 02:54:05 +00001165
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001166namespace __find_detail {
Marshall Clow15b02e02013-07-13 02:54:05 +00001167
Louis Dionne7dd28aa2021-07-20 11:46:05 -04001168static constexpr size_t __not_found = static_cast<size_t>(-1);
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001169static constexpr size_t __ambiguous = __not_found - 1;
Marshall Clow15b02e02013-07-13 02:54:05 +00001170
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001171inline _LIBCPP_INLINE_VISIBILITY
1172constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
1173 return !__matches ? __res :
1174 (__res == __not_found ? __curr_i : __ambiguous);
1175}
Marshall Clow15b02e02013-07-13 02:54:05 +00001176
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001177template <size_t _Nx>
1178inline _LIBCPP_INLINE_VISIBILITY
1179constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
1180 return __i == _Nx ? __not_found :
1181 __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
1182}
1183
1184template <class _T1, class ..._Args>
1185struct __find_exactly_one_checked {
Casey Carter7b5a7482017-12-12 17:22:24 +00001186 static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001187 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
Casey Carter7b5a7482017-12-12 17:22:24 +00001188 static_assert(value != __not_found, "type not found in type list" );
1189 static_assert(value != __ambiguous, "type occurs more than once in type list");
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001190};
1191
Eric Fiselier8087d302016-07-02 03:46:08 +00001192template <class _T1>
1193struct __find_exactly_one_checked<_T1> {
1194 static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
1195};
1196
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001197} // namespace __find_detail;
Marshall Clow15b02e02013-07-13 02:54:05 +00001198
1199template <typename _T1, typename... _Args>
Eric Fiselier2d0e2042016-07-02 03:18:30 +00001200struct __find_exactly_one_t
1201 : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
1202};
Marshall Clow15b02e02013-07-13 02:54:05 +00001203
1204template <class _T1, class... _Args>
1205inline _LIBCPP_INLINE_VISIBILITY
1206constexpr _T1& get(tuple<_Args...>& __tup) noexcept
1207{
1208 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1209}
1210
1211template <class _T1, class... _Args>
1212inline _LIBCPP_INLINE_VISIBILITY
1213constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
1214{
1215 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
1216}
1217
1218template <class _T1, class... _Args>
1219inline _LIBCPP_INLINE_VISIBILITY
1220constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
1221{
Marshall Clowfe9aa372013-07-15 20:46:11 +00001222 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
Marshall Clow15b02e02013-07-13 02:54:05 +00001223}
1224
Eric Fiselier6dea8092015-12-18 00:36:55 +00001225template <class _T1, class... _Args>
1226inline _LIBCPP_INLINE_VISIBILITY
1227constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
1228{
1229 return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
1230}
1231
Marshall Clow15b02e02013-07-13 02:54:05 +00001232#endif
1233
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234// tie
1235
1236template <class ..._Tp>
Marshall Clowa8892812014-02-25 16:11:46 +00001237inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238tuple<_Tp&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001239tie(_Tp&... __t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240{
1241 return tuple<_Tp&...>(__t...);
1242}
1243
1244template <class _Up>
1245struct __ignore_t
1246{
Howard Hinnantc51e1022010-05-11 19:42:16 +00001247 template <class _Tp>
Eric Fiselier24e70262017-02-06 01:25:31 +00001248 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1249 const __ignore_t& operator=(_Tp&&) const {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001250};
1251
Eric Fiselier24e70262017-02-06 01:25:31 +00001252namespace {
Louis Dionne559be102021-09-22 09:35:32 -04001253 constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
Eric Fiselier24e70262017-02-06 01:25:31 +00001254}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001255
Howard Hinnantc51e1022010-05-11 19:42:16 +00001256template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001257inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Louis Dionnedb1892a2018-12-03 14:03:27 +00001258tuple<typename __unwrap_ref_decay<_Tp>::type...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001259make_tuple(_Tp&&... __t)
1260{
Louis Dionnedb1892a2018-12-03 14:03:27 +00001261 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262}
1263
Howard Hinnant3d203a32010-08-19 18:59:38 +00001264template <class... _Tp>
Marshall Clow2229cee2013-07-22 16:02:19 +00001265inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1266tuple<_Tp&&...>
Howard Hinnant62751642012-07-06 21:53:48 +00001267forward_as_tuple(_Tp&&... __t) _NOEXCEPT
Howard Hinnant3d203a32010-08-19 18:59:38 +00001268{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001269 return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
Howard Hinnant3d203a32010-08-19 18:59:38 +00001270}
1271
Howard Hinnantc834c512011-11-29 18:15:50 +00001272template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001273struct __tuple_equal
1274{
1275 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001276 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277 bool operator()(const _Tp& __x, const _Up& __y)
1278 {
Marshall Clow60e4aa72014-06-24 00:46:19 +00001279 return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280 }
1281};
1282
1283template <>
1284struct __tuple_equal<0>
1285{
1286 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001288 bool operator()(const _Tp&, const _Up&)
1289 {
1290 return true;
1291 }
1292};
1293
1294template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001295inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296bool
1297operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1298{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001299 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001300 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
1301}
1302
1303template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001304inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305bool
1306operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1307{
1308 return !(__x == __y);
1309}
1310
Howard Hinnantc834c512011-11-29 18:15:50 +00001311template <size_t _Ip>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001312struct __tuple_less
1313{
1314 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001315 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001316 bool operator()(const _Tp& __x, const _Up& __y)
1317 {
Duncan P. N. Exon Smith6d3ec092015-01-21 02:51:17 +00001318 const size_t __idx = tuple_size<_Tp>::value - _Ip;
1319 if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
1320 return true;
1321 if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
1322 return false;
1323 return __tuple_less<_Ip-1>()(__x, __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324 }
1325};
1326
1327template <>
1328struct __tuple_less<0>
1329{
1330 template <class _Tp, class _Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001331 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001332 bool operator()(const _Tp&, const _Up&)
1333 {
1334 return false;
1335 }
1336};
1337
1338template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001339inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001340bool
1341operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1342{
Marshall Clow8ee1ddd2019-02-07 19:03:48 +00001343 static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001344 return __tuple_less<sizeof...(_Tp)>()(__x, __y);
1345}
1346
1347template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001348inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001349bool
1350operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1351{
1352 return __y < __x;
1353}
1354
1355template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001356inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001357bool
1358operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1359{
1360 return !(__x < __y);
1361}
1362
1363template <class ..._Tp, class ..._Up>
Marshall Clow2229cee2013-07-22 16:02:19 +00001364inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +00001365bool
1366operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
1367{
1368 return !(__y < __x);
1369}
1370
1371// tuple_cat
1372
Howard Hinnant6256ee72010-12-11 20:47:50 +00001373template <class _Tp, class _Up> struct __tuple_cat_type;
1374
1375template <class ..._Ttypes, class ..._Utypes>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001376struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001377{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001378 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001379};
1380
1381template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
1382struct __tuple_cat_return_1
1383{
1384};
1385
1386template <class ..._Types, class _Tuple0>
1387struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
1388{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001389 typedef _LIBCPP_NODEBUG typename __tuple_cat_type<tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001390 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001391 type;
1392};
1393
1394template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
1395struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1396 : public __tuple_cat_return_1<
1397 typename __tuple_cat_type<
1398 tuple<_Types...>,
Eric Fiselier0c8de4b2019-04-26 01:02:18 +00001399 typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
Howard Hinnant6256ee72010-12-11 20:47:50 +00001400 >::type,
1401 __tuple_like<typename remove_reference<_Tuple1>::type>::value,
1402 _Tuple1, _Tuples...>
1403{
1404};
1405
1406template <class ..._Tuples> struct __tuple_cat_return;
1407
1408template <class _Tuple0, class ..._Tuples>
1409struct __tuple_cat_return<_Tuple0, _Tuples...>
1410 : public __tuple_cat_return_1<tuple<>,
1411 __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
1412 _Tuples...>
1413{
1414};
1415
1416template <>
1417struct __tuple_cat_return<>
1418{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001419 typedef _LIBCPP_NODEBUG tuple<> type;
Howard Hinnant6256ee72010-12-11 20:47:50 +00001420};
1421
Marshall Clow2229cee2013-07-22 16:02:19 +00001422inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant6256ee72010-12-11 20:47:50 +00001423tuple<>
1424tuple_cat()
1425{
1426 return tuple<>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427}
1428
Howard Hinnantc834c512011-11-29 18:15:50 +00001429template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
Howard Hinnant21376f62010-12-12 23:04:37 +00001430struct __tuple_cat_return_ref_imp;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431
Howard Hinnant21376f62010-12-12 23:04:37 +00001432template <class ..._Types, size_t ..._I0, class _Tuple0>
1433struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001434{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001435 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001436 typedef tuple<_Types..., typename __apply_cv<_Tuple0,
1437 typename tuple_element<_I0, _T0>::type>::type&&...> type;
1438};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001439
Howard Hinnant21376f62010-12-12 23:04:37 +00001440template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
1441struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
1442 _Tuple0, _Tuple1, _Tuples...>
1443 : public __tuple_cat_return_ref_imp<
1444 tuple<_Types..., typename __apply_cv<_Tuple0,
1445 typename tuple_element<_I0,
1446 typename remove_reference<_Tuple0>::type>::type>::type&&...>,
1447 typename __make_tuple_indices<tuple_size<typename
1448 remove_reference<_Tuple1>::type>::value>::type,
1449 _Tuple1, _Tuples...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450{
Howard Hinnant21376f62010-12-12 23:04:37 +00001451};
1452
1453template <class _Tuple0, class ..._Tuples>
1454struct __tuple_cat_return_ref
1455 : public __tuple_cat_return_ref_imp<tuple<>,
1456 typename __make_tuple_indices<
1457 tuple_size<typename remove_reference<_Tuple0>::type>::value
1458 >::type, _Tuple0, _Tuples...>
1459{
1460};
1461
1462template <class _Types, class _I0, class _J0>
1463struct __tuple_cat;
1464
1465template <class ..._Types, size_t ..._I0, size_t ..._J0>
Howard Hinnant3a47c3d2011-01-24 16:07:25 +00001466struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
Howard Hinnant21376f62010-12-12 23:04:37 +00001467{
1468 template <class _Tuple0>
Marshall Clow2229cee2013-07-22 16:02:19 +00001469 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001470 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
1471 operator()(tuple<_Types...> __t, _Tuple0&& __t0)
1472 {
David Blaikie699a5e22019-10-28 18:03:59 -07001473 return _VSTD::forward_as_tuple(
1474 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1475 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001476 }
1477
1478 template <class _Tuple0, class _Tuple1, class ..._Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001479 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001480 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
1481 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
1482 {
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001483 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
1484 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple1>::type _T1;
Howard Hinnant21376f62010-12-12 23:04:37 +00001485 return __tuple_cat<
David Blaikie699a5e22019-10-28 18:03:59 -07001486 tuple<_Types...,
1487 typename __apply_cv<_Tuple0, typename tuple_element<
1488 _J0, _T0>::type>::type&&...>,
1489 typename __make_tuple_indices<sizeof...(_Types) +
1490 tuple_size<_T0>::value>::type,
1491 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
1492 _VSTD::forward_as_tuple(
1493 _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
1494 _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...),
1495 _VSTD::forward<_Tuple1>(__t1), _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnant21376f62010-12-12 23:04:37 +00001496 }
1497};
1498
1499template <class _Tuple0, class... _Tuples>
Marshall Clow2229cee2013-07-22 16:02:19 +00001500inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant21376f62010-12-12 23:04:37 +00001501typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1502tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
1503{
Louis Dionnea6c4ace2021-08-31 10:32:11 -04001504 typedef _LIBCPP_NODEBUG typename remove_reference<_Tuple0>::type _T0;
Howard Hinnant21376f62010-12-12 23:04:37 +00001505 return __tuple_cat<tuple<>, __tuple_indices<>,
1506 typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001507 (tuple<>(), _VSTD::forward<_Tuple0>(__t0),
1508 _VSTD::forward<_Tuples>(__tpls)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509}
1510
1511template <class ..._Tp, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001512struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001513 : true_type {};
1514
Howard Hinnantc51e1022010-05-11 19:42:16 +00001515template <class _T1, class _T2>
1516template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
Michael Schellenberger Costad41ace62020-09-02 21:20:33 +02001517inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518pair<_T1, _T2>::pair(piecewise_construct_t,
1519 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
1520 __tuple_indices<_I1...>, __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00001521 : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
1522 second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001523{
1524}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001525
Eric Fiselier8e892c52016-07-18 00:35:56 +00001526#if _LIBCPP_STD_VER > 14
1527template <class _Tp>
Louis Dionne559be102021-09-22 09:35:32 -04001528inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
Eric Fiselier8e892c52016-07-18 00:35:56 +00001529
1530#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1531
1532template <class _Fn, class _Tuple, size_t ..._Id>
1533inline _LIBCPP_INLINE_VISIBILITY
1534constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
1535 __tuple_indices<_Id...>)
1536_LIBCPP_NOEXCEPT_RETURN(
1537 _VSTD::__invoke_constexpr(
1538 _VSTD::forward<_Fn>(__f),
1539 _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
1540)
1541
1542template <class _Fn, class _Tuple>
1543inline _LIBCPP_INLINE_VISIBILITY
1544constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
1545_LIBCPP_NOEXCEPT_RETURN(
1546 _VSTD::__apply_tuple_impl(
1547 _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001548 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001549)
1550
1551template <class _Tp, class _Tuple, size_t... _Idx>
1552inline _LIBCPP_INLINE_VISIBILITY
1553constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
1554_LIBCPP_NOEXCEPT_RETURN(
1555 _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
1556)
1557
1558template <class _Tp, class _Tuple>
1559inline _LIBCPP_INLINE_VISIBILITY
1560constexpr _Tp make_from_tuple(_Tuple&& __t)
1561_LIBCPP_NOEXCEPT_RETURN(
1562 _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
Marshall Clowd5bbc242018-02-06 20:56:55 +00001563 typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
Eric Fiselier8e892c52016-07-18 00:35:56 +00001564)
1565
1566#undef _LIBCPP_NOEXCEPT_RETURN
1567
1568#endif // _LIBCPP_STD_VER > 14
1569
Eric Fiselierffe4aba2017-04-19 01:23:39 +00001570#endif // !defined(_LIBCPP_CXX03_LANG)
1571
Howard Hinnantc51e1022010-05-11 19:42:16 +00001572_LIBCPP_END_NAMESPACE_STD
1573
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001574#endif // _LIBCPP_TUPLE