Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP___TUPLE |
| 12 | #define _LIBCPP___TUPLE |
| 13 | |
| 14 | #include <__config> |
| 15 | #include <cstddef> |
| 16 | #include <type_traits> |
| 17 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 18 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 20 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | |
| 23 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 24 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 25 | template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY tuple_size; |
Howard Hinnant | 86ed8ae | 2010-11-17 19:22:43 +0000 | [diff] [blame] | 26 | |
| 27 | template <class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 28 | class _LIBCPP_TYPE_VIS_ONLY tuple_size<const _Tp> |
Howard Hinnant | 86ed8ae | 2010-11-17 19:22:43 +0000 | [diff] [blame] | 29 | : public tuple_size<_Tp> {}; |
| 30 | |
| 31 | template <class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 32 | class _LIBCPP_TYPE_VIS_ONLY tuple_size<volatile _Tp> |
Howard Hinnant | 86ed8ae | 2010-11-17 19:22:43 +0000 | [diff] [blame] | 33 | : public tuple_size<_Tp> {}; |
| 34 | |
| 35 | template <class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 36 | class _LIBCPP_TYPE_VIS_ONLY tuple_size<const volatile _Tp> |
Howard Hinnant | 86ed8ae | 2010-11-17 19:22:43 +0000 | [diff] [blame] | 37 | : public tuple_size<_Tp> {}; |
| 38 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 39 | template <size_t _Ip, class _Tp> class _LIBCPP_TYPE_VIS_ONLY tuple_element; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | |
Howard Hinnant | 86ed8ae | 2010-11-17 19:22:43 +0000 | [diff] [blame] | 41 | template <size_t _Ip, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 42 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, const _Tp> |
Howard Hinnant | 86ed8ae | 2010-11-17 19:22:43 +0000 | [diff] [blame] | 43 | { |
| 44 | public: |
| 45 | typedef typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type; |
| 46 | }; |
| 47 | |
| 48 | template <size_t _Ip, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 49 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, volatile _Tp> |
Howard Hinnant | 86ed8ae | 2010-11-17 19:22:43 +0000 | [diff] [blame] | 50 | { |
| 51 | public: |
| 52 | typedef typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type; |
| 53 | }; |
| 54 | |
| 55 | template <size_t _Ip, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 56 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, const volatile _Tp> |
Howard Hinnant | 86ed8ae | 2010-11-17 19:22:43 +0000 | [diff] [blame] | 57 | { |
| 58 | public: |
| 59 | typedef typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type; |
| 60 | }; |
| 61 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | template <class _Tp> struct __tuple_like : false_type {}; |
| 63 | |
Howard Hinnant | 0e1493e | 2010-12-11 20:47:50 +0000 | [diff] [blame] | 64 | template <class _Tp> struct __tuple_like<const _Tp> : public __tuple_like<_Tp> {}; |
| 65 | template <class _Tp> struct __tuple_like<volatile _Tp> : public __tuple_like<_Tp> {}; |
| 66 | template <class _Tp> struct __tuple_like<const volatile _Tp> : public __tuple_like<_Tp> {}; |
| 67 | |
Eric Fiselier | 8e706d2 | 2015-03-17 15:08:03 +0000 | [diff] [blame] | 68 | // tuple specializations |
| 69 | |
| 70 | #if !defined(_LIBCPP_HAS_NO_VARIADICS) |
| 71 | template <class ..._Tp> class _LIBCPP_TYPE_VIS_ONLY tuple; |
| 72 | |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 73 | template <class... _Tp> struct __tuple_like<tuple<_Tp...> > : true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 74 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 75 | template <size_t _Ip, class ..._Tp> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 76 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 77 | typename tuple_element<_Ip, tuple<_Tp...> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 78 | get(tuple<_Tp...>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 79 | |
| 80 | template <size_t _Ip, class ..._Tp> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 81 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 82 | const typename tuple_element<_Ip, tuple<_Tp...> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 83 | get(const tuple<_Tp...>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 85 | template <size_t _Ip, class ..._Tp> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 86 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 87 | typename tuple_element<_Ip, tuple<_Tp...> >::type&& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 88 | get(tuple<_Tp...>&&) _NOEXCEPT; |
Eric Fiselier | 8e706d2 | 2015-03-17 15:08:03 +0000 | [diff] [blame] | 89 | #endif |
| 90 | |
| 91 | // pair specializations |
| 92 | |
| 93 | template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY pair; |
| 94 | |
| 95 | template <class _T1, class _T2> struct __tuple_like<pair<_T1, _T2> > : true_type {}; |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 96 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 97 | template <size_t _Ip, class _T1, class _T2> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 98 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 99 | typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 100 | get(pair<_T1, _T2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 101 | |
| 102 | template <size_t _Ip, class _T1, class _T2> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 103 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 104 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 105 | get(const pair<_T1, _T2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 | |
Eric Fiselier | 8e706d2 | 2015-03-17 15:08:03 +0000 | [diff] [blame] | 107 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 108 | template <size_t _Ip, class _T1, class _T2> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 109 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 110 | typename tuple_element<_Ip, pair<_T1, _T2> >::type&& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 111 | get(pair<_T1, _T2>&&) _NOEXCEPT; |
Eric Fiselier | 8e706d2 | 2015-03-17 15:08:03 +0000 | [diff] [blame] | 112 | #endif |
| 113 | |
| 114 | // array specializations |
| 115 | |
| 116 | template <class _Tp, size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY array; |
| 117 | |
| 118 | template <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {}; |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 119 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 120 | template <size_t _Ip, class _Tp, size_t _Size> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 121 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 122 | _Tp& |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 123 | get(array<_Tp, _Size>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 124 | |
| 125 | template <size_t _Ip, class _Tp, size_t _Size> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 126 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 127 | const _Tp& |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 128 | get(const array<_Tp, _Size>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 129 | |
Eric Fiselier | 8e706d2 | 2015-03-17 15:08:03 +0000 | [diff] [blame] | 130 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 131 | template <size_t _Ip, class _Tp, size_t _Size> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 132 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 133 | _Tp&& |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 134 | get(array<_Tp, _Size>&&) _NOEXCEPT; |
Eric Fiselier | 8e706d2 | 2015-03-17 15:08:03 +0000 | [diff] [blame] | 135 | #endif |
| 136 | |
| 137 | #if !defined(_LIBCPP_HAS_NO_VARIADICS) |
| 138 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 139 | // __make_tuple_indices |
| 140 | |
| 141 | template <size_t...> struct __tuple_indices {}; |
| 142 | |
| 143 | template <size_t _Sp, class _IntTuple, size_t _Ep> |
| 144 | struct __make_indices_imp; |
| 145 | |
| 146 | template <size_t _Sp, size_t ..._Indices, size_t _Ep> |
| 147 | struct __make_indices_imp<_Sp, __tuple_indices<_Indices...>, _Ep> |
| 148 | { |
| 149 | typedef typename __make_indices_imp<_Sp+1, __tuple_indices<_Indices..., _Sp>, _Ep>::type type; |
| 150 | }; |
| 151 | |
| 152 | template <size_t _Ep, size_t ..._Indices> |
| 153 | struct __make_indices_imp<_Ep, __tuple_indices<_Indices...>, _Ep> |
| 154 | { |
| 155 | typedef __tuple_indices<_Indices...> type; |
| 156 | }; |
| 157 | |
| 158 | template <size_t _Ep, size_t _Sp = 0> |
| 159 | struct __make_tuple_indices |
| 160 | { |
| 161 | static_assert(_Sp <= _Ep, "__make_tuple_indices input error"); |
| 162 | typedef typename __make_indices_imp<_Sp, __tuple_indices<>, _Ep>::type type; |
| 163 | }; |
| 164 | |
| 165 | // __tuple_types |
| 166 | |
| 167 | template <class ..._Tp> struct __tuple_types {}; |
| 168 | |
| 169 | template <size_t _Ip> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 170 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, __tuple_types<> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 171 | { |
| 172 | public: |
| 173 | static_assert(_Ip == 0, "tuple_element index out of range"); |
| 174 | static_assert(_Ip != 0, "tuple_element index out of range"); |
| 175 | }; |
| 176 | |
| 177 | template <class _Hp, class ..._Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 178 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, __tuple_types<_Hp, _Tp...> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 179 | { |
| 180 | public: |
| 181 | typedef _Hp type; |
| 182 | }; |
| 183 | |
| 184 | template <size_t _Ip, class _Hp, class ..._Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 185 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, __tuple_types<_Hp, _Tp...> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | { |
| 187 | public: |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 188 | typedef typename tuple_element<_Ip-1, __tuple_types<_Tp...> >::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | template <class ..._Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 192 | class _LIBCPP_TYPE_VIS_ONLY tuple_size<__tuple_types<_Tp...> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 193 | : public integral_constant<size_t, sizeof...(_Tp)> |
| 194 | { |
| 195 | }; |
| 196 | |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 197 | template <class... _Tp> struct __tuple_like<__tuple_types<_Tp...> > : true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 198 | |
| 199 | // __make_tuple_types |
| 200 | |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame] | 201 | // __make_tuple_types<_Tuple<_Types...>, _Ep, _Sp>::type is a |
| 202 | // __tuple_types<_Types...> using only those _Types in the range [_Sp, _Ep). |
| 203 | // _Sp defaults to 0 and _Ep defaults to tuple_size<_Tuple>. If _Tuple is a |
| 204 | // lvalue_reference type, then __tuple_types<_Types&...> is the result. |
| 205 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 206 | template <class _TupleTypes, class _Tp, size_t _Sp, size_t _Ep> |
| 207 | struct __make_tuple_types_imp; |
| 208 | |
| 209 | template <class ..._Types, class _Tp, size_t _Sp, size_t _Ep> |
| 210 | struct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Sp, _Ep> |
| 211 | { |
| 212 | typedef typename remove_reference<_Tp>::type _Tpr; |
| 213 | typedef typename __make_tuple_types_imp<__tuple_types<_Types..., |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame] | 214 | typename conditional<is_lvalue_reference<_Tp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 215 | typename tuple_element<_Sp, _Tpr>::type&, |
| 216 | typename tuple_element<_Sp, _Tpr>::type>::type>, |
| 217 | _Tp, _Sp+1, _Ep>::type type; |
| 218 | }; |
| 219 | |
| 220 | template <class ..._Types, class _Tp, size_t _Ep> |
| 221 | struct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Ep, _Ep> |
| 222 | { |
| 223 | typedef __tuple_types<_Types...> type; |
| 224 | }; |
| 225 | |
| 226 | template <class _Tp, size_t _Ep = tuple_size<typename remove_reference<_Tp>::type>::value, size_t _Sp = 0> |
| 227 | struct __make_tuple_types |
| 228 | { |
| 229 | static_assert(_Sp <= _Ep, "__make_tuple_types input error"); |
| 230 | typedef typename __make_tuple_types_imp<__tuple_types<>, _Tp, _Sp, _Ep>::type type; |
| 231 | }; |
| 232 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 233 | // __tuple_convertible |
| 234 | |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 235 | template <class, class> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 236 | struct __tuple_convertible_imp : public false_type {}; |
| 237 | |
| 238 | template <class _Tp0, class ..._Tp, class _Up0, class ..._Up> |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 239 | struct __tuple_convertible_imp<__tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 240 | : public integral_constant<bool, |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 241 | is_convertible<_Tp0, _Up0>::value && |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 242 | __tuple_convertible_imp<__tuple_types<_Tp...>, __tuple_types<_Up...> >::value> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 243 | |
| 244 | template <> |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 245 | struct __tuple_convertible_imp<__tuple_types<>, __tuple_types<> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 246 | : public true_type {}; |
| 247 | |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 248 | template <bool, class, class> |
| 249 | struct __tuple_convertible_apply : public false_type {}; |
| 250 | |
| 251 | template <class _Tp, class _Up> |
| 252 | struct __tuple_convertible_apply<true, _Tp, _Up> |
| 253 | : public __tuple_convertible_imp< |
| 254 | typename __make_tuple_types<_Tp>::type |
| 255 | , typename __make_tuple_types<_Up>::type |
| 256 | > |
| 257 | {}; |
| 258 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 259 | template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value, |
| 260 | bool = __tuple_like<_Up>::value> |
| 261 | struct __tuple_convertible |
| 262 | : public false_type {}; |
| 263 | |
| 264 | template <class _Tp, class _Up> |
| 265 | struct __tuple_convertible<_Tp, _Up, true, true> |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 266 | : public __tuple_convertible_apply<tuple_size<typename remove_reference<_Tp>::type>::value == |
| 267 | tuple_size<_Up>::value, _Tp, _Up> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | {}; |
| 269 | |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 270 | // __tuple_constructible |
| 271 | |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 272 | template <class, class> |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 273 | struct __tuple_constructible_imp : public false_type {}; |
| 274 | |
| 275 | template <class _Tp0, class ..._Tp, class _Up0, class ..._Up> |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 276 | struct __tuple_constructible_imp<__tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...> > |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 277 | : public integral_constant<bool, |
| 278 | is_constructible<_Up0, _Tp0>::value && |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 279 | __tuple_constructible_imp<__tuple_types<_Tp...>, __tuple_types<_Up...> >::value> {}; |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 280 | |
| 281 | template <> |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 282 | struct __tuple_constructible_imp<__tuple_types<>, __tuple_types<> > |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 283 | : public true_type {}; |
| 284 | |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 285 | template <bool _SameSize, class, class> |
| 286 | struct __tuple_constructible_apply : public false_type {}; |
| 287 | |
| 288 | template <class _Tp, class _Up> |
| 289 | struct __tuple_constructible_apply<true, _Tp, _Up> |
| 290 | : public __tuple_constructible_imp< |
| 291 | typename __make_tuple_types<_Tp>::type |
| 292 | , typename __make_tuple_types<_Up>::type |
| 293 | > |
| 294 | {}; |
| 295 | |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 296 | template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value, |
| 297 | bool = __tuple_like<_Up>::value> |
| 298 | struct __tuple_constructible |
| 299 | : public false_type {}; |
| 300 | |
| 301 | template <class _Tp, class _Up> |
| 302 | struct __tuple_constructible<_Tp, _Up, true, true> |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 303 | : public __tuple_constructible_apply<tuple_size<typename remove_reference<_Tp>::type>::value == |
| 304 | tuple_size<_Up>::value, _Tp, _Up> |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 305 | {}; |
| 306 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 307 | // __tuple_assignable |
| 308 | |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 309 | template <class, class> |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame] | 310 | struct __tuple_assignable_imp : public false_type {}; |
| 311 | |
| 312 | template <class _Tp0, class ..._Tp, class _Up0, class ..._Up> |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 313 | struct __tuple_assignable_imp<__tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...> > |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame] | 314 | : public integral_constant<bool, |
Howard Hinnant | f048fe3 | 2010-11-20 18:25:22 +0000 | [diff] [blame] | 315 | is_assignable<_Up0&, _Tp0>::value && |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 316 | __tuple_assignable_imp<__tuple_types<_Tp...>, __tuple_types<_Up...> >::value> {}; |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame] | 317 | |
| 318 | template <> |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 319 | struct __tuple_assignable_imp<__tuple_types<>, __tuple_types<> > |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame] | 320 | : public true_type {}; |
| 321 | |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 322 | template <bool, class, class> |
| 323 | struct __tuple_assignable_apply : public false_type {}; |
| 324 | |
| 325 | template <class _Tp, class _Up> |
| 326 | struct __tuple_assignable_apply<true, _Tp, _Up> |
| 327 | : __tuple_assignable_imp< |
| 328 | typename __make_tuple_types<_Tp>::type |
| 329 | , typename __make_tuple_types<_Up>::type |
| 330 | > |
| 331 | {}; |
| 332 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 333 | template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value, |
| 334 | bool = __tuple_like<_Up>::value> |
| 335 | struct __tuple_assignable |
| 336 | : public false_type {}; |
| 337 | |
| 338 | template <class _Tp, class _Up> |
| 339 | struct __tuple_assignable<_Tp, _Up, true, true> |
Eric Fiselier | 522aaf6 | 2014-10-28 06:31:22 +0000 | [diff] [blame] | 340 | : public __tuple_assignable_apply<tuple_size<typename remove_reference<_Tp>::type>::value == |
| 341 | tuple_size<_Up>::value, _Tp, _Up> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 342 | {}; |
| 343 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 344 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 345 | |
Eric Fiselier | 8e706d2 | 2015-03-17 15:08:03 +0000 | [diff] [blame] | 346 | _LIBCPP_END_NAMESPACE_STD |
| 347 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 348 | #endif // _LIBCPP___TUPLE |