blob: 69d6ee961113149e77d5a768e942feb32eb6e551 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP___TUPLE
12#define _LIBCPP___TUPLE
13
14#include <__config>
15#include <cstddef>
16#include <type_traits>
17
Howard Hinnant08e17472011-10-17 20:05:10 +000018#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +000020#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022
23_LIBCPP_BEGIN_NAMESPACE_STD
24
Eric Fiselierc3589a82017-01-04 23:56:00 +000025template <class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_size;
Eric Fiselier40843842017-01-02 23:54:13 +000026
Eric Fiselier06a0feb2017-01-04 22:38:46 +000027#if !defined(_LIBCPP_CXX03_LANG)
28template <class _Tp, class...>
29using __enable_if_tuple_size_imp = _Tp;
Eric Fiselier40843842017-01-02 23:54:13 +000030
31template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +000032class _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
Eric Fiselier06a0feb2017-01-04 22:38:46 +000033 const _Tp,
34 typename enable_if<!is_volatile<_Tp>::value>::type,
35 integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
36 : public integral_constant<size_t, tuple_size<_Tp>::value> {};
Howard Hinnant86ed8ae2010-11-17 19:22:43 +000037
38template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +000039class _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
Eric Fiselier06a0feb2017-01-04 22:38:46 +000040 volatile _Tp,
41 typename enable_if<!is_const<_Tp>::value>::type,
42 integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
43 : public integral_constant<size_t, tuple_size<_Tp>::value> {};
Howard Hinnant86ed8ae2010-11-17 19:22:43 +000044
45template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +000046class _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
Eric Fiselier06a0feb2017-01-04 22:38:46 +000047 const volatile _Tp,
48 integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
49 : public integral_constant<size_t, tuple_size<_Tp>::value> {};
Howard Hinnant86ed8ae2010-11-17 19:22:43 +000050
Eric Fiselier06a0feb2017-01-04 22:38:46 +000051#else
Eric Fiselierc3589a82017-01-04 23:56:00 +000052template <class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_size<const _Tp> : public tuple_size<_Tp> {};
53template <class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_size<volatile _Tp> : public tuple_size<_Tp> {};
54template <class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_size<const volatile _Tp> : public tuple_size<_Tp> {};
Eric Fiselier06a0feb2017-01-04 22:38:46 +000055#endif
Howard Hinnant86ed8ae2010-11-17 19:22:43 +000056
Eric Fiselierc3589a82017-01-04 23:56:00 +000057template <size_t _Ip, class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_element;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000058
Howard Hinnant86ed8ae2010-11-17 19:22:43 +000059template <size_t _Ip, class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +000060class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp>
Howard Hinnant86ed8ae2010-11-17 19:22:43 +000061{
62public:
63 typedef typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
64};
65
66template <size_t _Ip, class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +000067class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp>
Howard Hinnant86ed8ae2010-11-17 19:22:43 +000068{
69public:
70 typedef typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
71};
72
73template <size_t _Ip, class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +000074class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp>
Howard Hinnant86ed8ae2010-11-17 19:22:43 +000075{
76public:
77 typedef typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
78};
79
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000080template <class _Tp> struct __tuple_like : false_type {};
81
Howard Hinnant0e1493e2010-12-11 20:47:50 +000082template <class _Tp> struct __tuple_like<const _Tp> : public __tuple_like<_Tp> {};
83template <class _Tp> struct __tuple_like<volatile _Tp> : public __tuple_like<_Tp> {};
84template <class _Tp> struct __tuple_like<const volatile _Tp> : public __tuple_like<_Tp> {};
85
Eric Fiselier8e706d22015-03-17 15:08:03 +000086// tuple specializations
87
Eric Fiselier191f0752017-04-19 01:23:39 +000088#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera3ccd962016-06-30 22:34:43 +000089
90template <size_t...> struct __tuple_indices {};
91
92template <class _IdxType, _IdxType... _Values>
93struct __integer_sequence {
94 template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType>
95 using __convert = _ToIndexSeq<_ToIndexType, _Values...>;
96
97 template <size_t _Sp>
98 using __to_tuple_indices = __tuple_indices<(_Values + _Sp)...>;
99};
100
101#if !__has_builtin(__make_integer_seq) || defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
102namespace __detail {
103
104template<typename _Tp, size_t ..._Extra> struct __repeat;
105template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> {
106 typedef __integer_sequence<_Tp,
107 _Np...,
108 sizeof...(_Np) + _Np...,
109 2 * sizeof...(_Np) + _Np...,
110 3 * sizeof...(_Np) + _Np...,
111 4 * sizeof...(_Np) + _Np...,
112 5 * sizeof...(_Np) + _Np...,
113 6 * sizeof...(_Np) + _Np...,
114 7 * sizeof...(_Np) + _Np...,
115 _Extra...> type;
116};
117
118template<size_t _Np> struct __parity;
119template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
120
121template<> struct __make<0> { typedef __integer_sequence<size_t> type; };
122template<> struct __make<1> { typedef __integer_sequence<size_t, 0> type; };
123template<> struct __make<2> { typedef __integer_sequence<size_t, 0, 1> type; };
124template<> struct __make<3> { typedef __integer_sequence<size_t, 0, 1, 2> type; };
125template<> struct __make<4> { typedef __integer_sequence<size_t, 0, 1, 2, 3> type; };
126template<> struct __make<5> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
127template<> struct __make<6> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
128template<> struct __make<7> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; };
129
130template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; };
131template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
132template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
133template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
134template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
135template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
136template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
137template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
138
139} // namespace detail
140
141#endif // !__has_builtin(__make_integer_seq) || defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
142
143#if __has_builtin(__make_integer_seq)
144template <size_t _Ep, size_t _Sp>
145using __make_indices_imp =
146 typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template
147 __to_tuple_indices<_Sp>;
148#else
149template <size_t _Ep, size_t _Sp>
150using __make_indices_imp =
151 typename __detail::__make<_Ep - _Sp>::type::template __to_tuple_indices<_Sp>;
152
153#endif
154
155template <size_t _Ep, size_t _Sp = 0>
156struct __make_tuple_indices
157{
158 static_assert(_Sp <= _Ep, "__make_tuple_indices input error");
159 typedef __make_indices_imp<_Ep, _Sp> type;
160};
161
162
Eric Fiselierc3589a82017-01-04 23:56:00 +0000163template <class ..._Tp> class _LIBCPP_TEMPLATE_VIS tuple;
Eric Fiselier8e706d22015-03-17 15:08:03 +0000164
Howard Hinnantf83417b2011-01-24 16:07:25 +0000165template <class... _Tp> struct __tuple_like<tuple<_Tp...> > : true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000166
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000167template <class ..._Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000168class _LIBCPP_TEMPLATE_VIS tuple_size<tuple<_Tp...> >
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000169 : public integral_constant<size_t, sizeof...(_Tp)>
170{
171};
172
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000173template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000174_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000175typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000176get(tuple<_Tp...>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000177
178template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000179_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000180const typename tuple_element<_Ip, tuple<_Tp...> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000181get(const tuple<_Tp...>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000182
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000183template <size_t _Ip, class ..._Tp>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000184_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantf83417b2011-01-24 16:07:25 +0000185typename tuple_element<_Ip, tuple<_Tp...> >::type&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000186get(tuple<_Tp...>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000187
188template <size_t _Ip, class ..._Tp>
189_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
190const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
191get(const tuple<_Tp...>&&) _NOEXCEPT;
Eric Fiselier191f0752017-04-19 01:23:39 +0000192
193#endif // !defined(_LIBCPP_CXX03_LANG)
Eric Fiselier8e706d22015-03-17 15:08:03 +0000194
195// pair specializations
196
Eric Fiselier8e706d22015-03-17 15:08:03 +0000197template <class _T1, class _T2> struct __tuple_like<pair<_T1, _T2> > : true_type {};
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000198
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000199template <size_t _Ip, class _T1, class _T2>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000200_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000202get(pair<_T1, _T2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000203
204template <size_t _Ip, class _T1, class _T2>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000205_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000206const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000207get(const pair<_T1, _T2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208
Eric Fiselier191f0752017-04-19 01:23:39 +0000209#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000210template <size_t _Ip, class _T1, class _T2>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000211_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000212typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
Howard Hinnanta5e01212011-05-27 19:08:18 +0000213get(pair<_T1, _T2>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000214
215template <size_t _Ip, class _T1, class _T2>
216_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
217const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
218get(const pair<_T1, _T2>&&) _NOEXCEPT;
Eric Fiselier8e706d22015-03-17 15:08:03 +0000219#endif
220
221// array specializations
222
Eric Fiselierc3589a82017-01-04 23:56:00 +0000223template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;
Eric Fiselier8e706d22015-03-17 15:08:03 +0000224
225template <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {};
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000226
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000227template <size_t _Ip, class _Tp, size_t _Size>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000228_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000229_Tp&
Howard Hinnantf0562af2011-05-31 21:06:33 +0000230get(array<_Tp, _Size>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231
232template <size_t _Ip, class _Tp, size_t _Size>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000233_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000234const _Tp&
Howard Hinnantf0562af2011-05-31 21:06:33 +0000235get(const array<_Tp, _Size>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000236
Eric Fiselier191f0752017-04-19 01:23:39 +0000237#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000238template <size_t _Ip, class _Tp, size_t _Size>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000239_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000240_Tp&&
Howard Hinnantf0562af2011-05-31 21:06:33 +0000241get(array<_Tp, _Size>&&) _NOEXCEPT;
Eric Fiselier199bee02015-12-18 00:36:55 +0000242
243template <size_t _Ip, class _Tp, size_t _Size>
244_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
245const _Tp&&
246get(const array<_Tp, _Size>&&) _NOEXCEPT;
Eric Fiselier8e706d22015-03-17 15:08:03 +0000247#endif
248
Eric Fiselier191f0752017-04-19 01:23:39 +0000249#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250
251// __tuple_types
252
253template <class ..._Tp> struct __tuple_types {};
254
Eric Fiselier053859f2016-07-01 03:54:54 +0000255#if !__has_builtin(__type_pack_element)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256
Eric Fiselier053859f2016-07-01 03:54:54 +0000257namespace __indexer_detail {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258
Eric Fiselier053859f2016-07-01 03:54:54 +0000259template <size_t _Idx, class _Tp>
260struct __indexed { using type = _Tp; };
261
262template <class _Types, class _Indexes> struct __indexer;
263
264template <class ..._Types, size_t ..._Idx>
265struct __indexer<__tuple_types<_Types...>, __tuple_indices<_Idx...>>
266 : __indexed<_Idx, _Types>...
267{};
268
269template <size_t _Idx, class _Tp>
270__indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&);
271
272} // namespace __indexer_detail
273
274template <size_t _Idx, class ..._Types>
275using __type_pack_element = typename decltype(
276 __indexer_detail::__at_index<_Idx>(
277 __indexer_detail::__indexer<
278 __tuple_types<_Types...>,
279 typename __make_tuple_indices<sizeof...(_Types)>::type
280 >{})
281 )::type;
Eric Fiselier053859f2016-07-01 03:54:54 +0000282#endif
283
284template <size_t _Ip, class ..._Types>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000285class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286{
287public:
Eric Fiselier053859f2016-07-01 03:54:54 +0000288 static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
289 typedef __type_pack_element<_Ip, _Types...> type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290};
291
Eric Fiseliered33ed82016-07-01 04:07:39 +0000292
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293template <class ..._Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000294class _LIBCPP_TEMPLATE_VIS tuple_size<__tuple_types<_Tp...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000295 : public integral_constant<size_t, sizeof...(_Tp)>
296{
297};
298
Howard Hinnantf83417b2011-01-24 16:07:25 +0000299template <class... _Tp> struct __tuple_like<__tuple_types<_Tp...> > : true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000300
Eric Fiselier053859f2016-07-01 03:54:54 +0000301template <bool _ApplyLV, bool _ApplyConst, bool _ApplyVolatile>
302struct __apply_cv_mf;
303template <>
304struct __apply_cv_mf<false, false, false> {
305 template <class _Tp> using __apply = _Tp;
306};
307template <>
308struct __apply_cv_mf<false, true, false> {
309 template <class _Tp> using __apply = const _Tp;
310};
311template <>
312struct __apply_cv_mf<false, false, true> {
313 template <class _Tp> using __apply = volatile _Tp;
314};
315template <>
316struct __apply_cv_mf<false, true, true> {
317 template <class _Tp> using __apply = const volatile _Tp;
318};
319template <>
320struct __apply_cv_mf<true, false, false> {
321 template <class _Tp> using __apply = _Tp&;
322};
323template <>
324struct __apply_cv_mf<true, true, false> {
325 template <class _Tp> using __apply = const _Tp&;
326};
327template <>
328struct __apply_cv_mf<true, false, true> {
329 template <class _Tp> using __apply = volatile _Tp&;
330};
331template <>
332struct __apply_cv_mf<true, true, true> {
333 template <class _Tp> using __apply = const volatile _Tp&;
334};
335template <class _Tp, class _RawTp = typename remove_reference<_Tp>::type>
336using __apply_cv_t = __apply_cv_mf<
337 is_lvalue_reference<_Tp>::value,
338 is_const<_RawTp>::value,
339 is_volatile<_RawTp>::value>;
340
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341// __make_tuple_types
342
Howard Hinnante049cc52010-09-27 17:54:17 +0000343// __make_tuple_types<_Tuple<_Types...>, _Ep, _Sp>::type is a
344// __tuple_types<_Types...> using only those _Types in the range [_Sp, _Ep).
345// _Sp defaults to 0 and _Ep defaults to tuple_size<_Tuple>. If _Tuple is a
346// lvalue_reference type, then __tuple_types<_Types&...> is the result.
347
Eric Fiselier053859f2016-07-01 03:54:54 +0000348template <class _TupleTypes, class _TupleIndices>
349struct __make_tuple_types_flat;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350
Eric Fiselier053859f2016-07-01 03:54:54 +0000351template <template <class...> class _Tuple, class ..._Types, size_t ..._Idx>
352struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> {
353 // Specialization for pair, tuple, and __tuple_types
354 template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>>
355 using __apply_quals = __tuple_types<
356 typename _ApplyFn::template __apply<__type_pack_element<_Idx, _Types...>>...
357 >;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358};
359
Eric Fiselier053859f2016-07-01 03:54:54 +0000360template <class _Vt, size_t _Np, size_t ..._Idx>
361struct __make_tuple_types_flat<array<_Vt, _Np>, __tuple_indices<_Idx...>> {
Eric Fiselier5fb1e0a2016-07-02 01:25:46 +0000362 template <size_t>
363 using __value_type = _Vt;
Eric Fiselier053859f2016-07-01 03:54:54 +0000364 template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>>
365 using __apply_quals = __tuple_types<
Eric Fiselier5fb1e0a2016-07-02 01:25:46 +0000366 typename _ApplyFn::template __apply<__value_type<_Idx>>...
Eric Fiselier053859f2016-07-01 03:54:54 +0000367 >;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368};
369
Eric Fiselier053859f2016-07-01 03:54:54 +0000370template <class _Tp, size_t _Ep = tuple_size<typename remove_reference<_Tp>::type>::value,
371 size_t _Sp = 0,
372 bool _SameSize = (_Ep == tuple_size<typename remove_reference<_Tp>::type>::value)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373struct __make_tuple_types
374{
375 static_assert(_Sp <= _Ep, "__make_tuple_types input error");
Eric Fiselier053859f2016-07-01 03:54:54 +0000376 using _RawTp = typename remove_cv<typename remove_reference<_Tp>::type>::type;
377 using _Maker = __make_tuple_types_flat<_RawTp, typename __make_tuple_indices<_Ep, _Sp>::type>;
378 using type = typename _Maker::template __apply_quals<_Tp>;
379};
380
381template <class ..._Types, size_t _Ep>
382struct __make_tuple_types<tuple<_Types...>, _Ep, 0, true> {
383 typedef __tuple_types<_Types...> type;
384};
385
386template <class ..._Types, size_t _Ep>
387struct __make_tuple_types<__tuple_types<_Types...>, _Ep, 0, true> {
388 typedef __tuple_types<_Types...> type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389};
390
Eric Fiseliered33ed82016-07-01 04:07:39 +0000391template <bool ..._Preds>
392struct __all_dummy;
393
394template <bool ..._Pred>
Eric Fiselier3ec6b842016-08-29 20:43:38 +0000395using __all = is_same<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>>;
Eric Fiseliered33ed82016-07-01 04:07:39 +0000396
397struct __tuple_sfinae_base {
Eric Fiselier5fb1e0a2016-07-02 01:25:46 +0000398 template <template <class, class...> class _Trait,
399 class ..._LArgs, class ..._RArgs>
400 static auto __do_test(__tuple_types<_LArgs...>, __tuple_types<_RArgs...>)
401 -> __all<typename enable_if<_Trait<_LArgs, _RArgs>::value, bool>::type{true}...>;
402 template <template <class...> class>
403 static auto __do_test(...) -> false_type;
Eric Fiseliered33ed82016-07-01 04:07:39 +0000404
Eric Fiselier5fb1e0a2016-07-02 01:25:46 +0000405 template <class _FromArgs, class _ToArgs>
406 using __constructible = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{}));
407 template <class _FromArgs, class _ToArgs>
408 using __convertible = decltype(__do_test<is_convertible>(_FromArgs{}, _ToArgs{}));
409 template <class _FromArgs, class _ToArgs>
410 using __assignable = decltype(__do_test<is_assignable>(_ToArgs{}, _FromArgs{}));
Eric Fiseliered33ed82016-07-01 04:07:39 +0000411};
412
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413// __tuple_convertible
414
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
416 bool = __tuple_like<_Up>::value>
417struct __tuple_convertible
418 : public false_type {};
419
420template <class _Tp, class _Up>
421struct __tuple_convertible<_Tp, _Up, true, true>
Eric Fiseliered33ed82016-07-01 04:07:39 +0000422 : public __tuple_sfinae_base::__convertible<
Eric Fiselier522aaf62014-10-28 06:31:22 +0000423 typename __make_tuple_types<_Tp>::type
424 , typename __make_tuple_types<_Up>::type
425 >
426{};
427
Eric Fiseliered33ed82016-07-01 04:07:39 +0000428// __tuple_constructible
429
Howard Hinnantdc1345f2012-04-01 23:10:42 +0000430template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
431 bool = __tuple_like<_Up>::value>
432struct __tuple_constructible
433 : public false_type {};
434
435template <class _Tp, class _Up>
436struct __tuple_constructible<_Tp, _Up, true, true>
Eric Fiseliered33ed82016-07-01 04:07:39 +0000437 : public __tuple_sfinae_base::__constructible<
Eric Fiselier522aaf62014-10-28 06:31:22 +0000438 typename __make_tuple_types<_Tp>::type
439 , typename __make_tuple_types<_Up>::type
440 >
441{};
442
Eric Fiseliered33ed82016-07-01 04:07:39 +0000443// __tuple_assignable
444
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
446 bool = __tuple_like<_Up>::value>
447struct __tuple_assignable
448 : public false_type {};
449
450template <class _Tp, class _Up>
451struct __tuple_assignable<_Tp, _Up, true, true>
Eric Fiseliered33ed82016-07-01 04:07:39 +0000452 : public __tuple_sfinae_base::__assignable<
453 typename __make_tuple_types<_Tp>::type
Eric Fiselier5fb1e0a2016-07-02 01:25:46 +0000454 , typename __make_tuple_types<_Up&>::type
Eric Fiseliered33ed82016-07-01 04:07:39 +0000455 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000456{};
457
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000458
459template <size_t _Ip, class ..._Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000460class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> >
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000461{
462public:
463 typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
464};
465
466#if _LIBCPP_STD_VER > 11
467template <size_t _Ip, class ..._Tp>
468using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type;
469#endif
470
Eric Fiselier9663ee42016-12-15 06:34:54 +0000471template <bool _IsTuple, class _SizeTrait, size_t _Expected>
472struct __tuple_like_with_size_imp : false_type {};
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000473
Eric Fiselier9663ee42016-12-15 06:34:54 +0000474template <class _SizeTrait, size_t _Expected>
475struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
476 : integral_constant<bool, _SizeTrait::value == _Expected> {};
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000477
Eric Fiselier9663ee42016-12-15 06:34:54 +0000478template <class _Tuple, size_t _ExpectedSize,
479 class _RawTuple = typename __uncvref<_Tuple>::type>
480using __tuple_like_with_size = __tuple_like_with_size_imp<
481 __tuple_like<_RawTuple>::value,
482 tuple_size<_RawTuple>, _ExpectedSize
483 >;
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000484
485struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail {
486 template <class ...>
487 static constexpr bool __enable_default() { return false; }
488 template <class ...>
489 static constexpr bool __enable_explicit() { return false; }
490 template <class ...>
491 static constexpr bool __enable_implicit() { return false; }
492 template <class ...>
493 static constexpr bool __enable_assign() { return false; }
494};
Eric Fiselier191f0752017-04-19 01:23:39 +0000495#endif // !defined(_LIBCPP_CXX03_LANG)
Eric Fiseliere1445fd2016-07-25 04:32:07 +0000496
Eric Fiselierb901c342016-08-15 01:51:54 +0000497#if _LIBCPP_STD_VER > 14
498
499template <bool _CanCopy, bool _CanMove>
500struct __sfinae_ctor_base {};
501template <>
502struct __sfinae_ctor_base<false, false> {
503 __sfinae_ctor_base() = default;
504 __sfinae_ctor_base(__sfinae_ctor_base const&) = delete;
505 __sfinae_ctor_base(__sfinae_ctor_base &&) = delete;
506 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
507 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
508};
509template <>
510struct __sfinae_ctor_base<true, false> {
511 __sfinae_ctor_base() = default;
512 __sfinae_ctor_base(__sfinae_ctor_base const&) = default;
513 __sfinae_ctor_base(__sfinae_ctor_base &&) = delete;
514 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
515 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
516};
517template <>
518struct __sfinae_ctor_base<false, true> {
519 __sfinae_ctor_base() = default;
520 __sfinae_ctor_base(__sfinae_ctor_base const&) = delete;
521 __sfinae_ctor_base(__sfinae_ctor_base &&) = default;
522 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
523 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
524};
525
526template <bool _CanCopy, bool _CanMove>
527struct __sfinae_assign_base {};
528template <>
529struct __sfinae_assign_base<false, false> {
530 __sfinae_assign_base() = default;
531 __sfinae_assign_base(__sfinae_assign_base const&) = default;
532 __sfinae_assign_base(__sfinae_assign_base &&) = default;
533 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete;
534 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete;
535};
536template <>
537struct __sfinae_assign_base<true, false> {
538 __sfinae_assign_base() = default;
539 __sfinae_assign_base(__sfinae_assign_base const&) = default;
540 __sfinae_assign_base(__sfinae_assign_base &&) = default;
541 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = default;
542 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete;
543};
544template <>
545struct __sfinae_assign_base<false, true> {
546 __sfinae_assign_base() = default;
547 __sfinae_assign_base(__sfinae_assign_base const&) = default;
548 __sfinae_assign_base(__sfinae_assign_base &&) = default;
549 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete;
550 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = default;
551};
552#endif // _LIBCPP_STD_VER > 14
553
Eric Fiselier8e706d22015-03-17 15:08:03 +0000554_LIBCPP_END_NAMESPACE_STD
555
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556#endif // _LIBCPP___TUPLE