Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- tuple ------------------------------------===// |
| 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 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_TUPLE |
| 12 | #define _LIBCPP_TUPLE |
| 13 | |
| 14 | /* |
| 15 | tuple synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class... T> |
| 21 | class tuple { |
| 22 | public: |
| 23 | constexpr tuple(); |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 24 | explicit tuple(const T&...); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 25 | template <class... U> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 26 | explicit tuple(U&&...); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 27 | tuple(const tuple&) = default; |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 28 | tuple(tuple&&) = default; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 29 | template <class... U> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 30 | tuple(const tuple<U...>&); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | template <class... U> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 32 | tuple(tuple<U...>&&); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | template <class U1, class U2> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 34 | tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | template <class U1, class U2> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 36 | tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 37 | |
| 38 | // allocator-extended constructors |
| 39 | template <class Alloc> |
| 40 | tuple(allocator_arg_t, const Alloc& a); |
| 41 | template <class Alloc> |
| 42 | tuple(allocator_arg_t, const Alloc& a, const T&...); |
| 43 | template <class Alloc, class... U> |
| 44 | tuple(allocator_arg_t, const Alloc& a, U&&...); |
| 45 | template <class Alloc> |
| 46 | tuple(allocator_arg_t, const Alloc& a, const tuple&); |
| 47 | template <class Alloc> |
| 48 | tuple(allocator_arg_t, const Alloc& a, tuple&&); |
| 49 | template <class Alloc, class... U> |
| 50 | tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); |
| 51 | template <class Alloc, class... U> |
| 52 | tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); |
| 53 | template <class Alloc, class U1, class U2> |
| 54 | tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); |
| 55 | template <class Alloc, class U1, class U2> |
| 56 | tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); |
| 57 | |
| 58 | tuple& operator=(const tuple&); |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 59 | tuple& |
| 60 | operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 61 | template <class... U> |
| 62 | tuple& operator=(const tuple<U...>&); |
| 63 | template <class... U> |
| 64 | tuple& operator=(tuple<U...>&&); |
| 65 | template <class U1, class U2> |
| 66 | tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 |
| 67 | template <class U1, class U2> |
| 68 | tuple& operator=(pair<U1, U2>&&); //iffsizeof...(T) == 2 |
| 69 | |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 70 | void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | const unspecified ignore; |
| 74 | |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 75 | template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14 |
Marshall Clow | 1d927e3 | 2013-10-05 18:46:37 +0000 | [diff] [blame] | 76 | template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14 |
Marshall Clow | 8e554d9 | 2014-02-25 16:11:46 +0000 | [diff] [blame] | 77 | template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14 |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 78 | template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14 |
Eric Fiselier | 5839fed | 2016-07-18 00:35:56 +0000 | [diff] [blame^] | 79 | |
| 80 | // [tuple.apply], calling a function with a tuple of arguments: |
| 81 | template <class F, class Tuple> |
| 82 | constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17 |
| 83 | template <class T, class Tuple> |
| 84 | constexpr T make_from_tuple(Tuple&& t); // C++17 |
| 85 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 86 | // 20.4.1.4, tuple helper classes: |
| 87 | template <class T> class tuple_size; // undefined |
| 88 | template <class... T> class tuple_size<tuple<T...>>; |
Eric Fiselier | 5839fed | 2016-07-18 00:35:56 +0000 | [diff] [blame^] | 89 | template <class T> |
| 90 | constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17 |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 91 | template <size_t I, class T> class tuple_element; // undefined |
| 92 | template <size_t I, class... T> class tuple_element<I, tuple<T...>>; |
| 93 | template <size_t I, class T> |
| 94 | using tuple_element_t = typename tuple_element <I, T>::type; // C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 95 | |
| 96 | // 20.4.1.5, element access: |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 97 | template <size_t I, class... T> |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 98 | typename tuple_element<I, tuple<T...>>::type& |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 99 | get(tuple<T...>&) noexcept; // constexpr in C++14 |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 100 | template <size_t I, class... T> |
| 101 | const typename tuple_element<I, tuple<T...>>::type& |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 102 | get(const tuple<T...>&) noexcept; // constexpr in C++14 |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 103 | template <size_t I, class... T> |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 104 | typename tuple_element<I, tuple<T...>>::type&& |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 105 | get(tuple<T...>&&) noexcept; // constexpr in C++14 |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 106 | template <size_t I, class... T> |
| 107 | const typename tuple_element<I, tuple<T...>>::type&& |
| 108 | get(const tuple<T...>&&) noexcept; // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 109 | |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 110 | template <class T1, class... T> |
| 111 | constexpr T1& get(tuple<T...>&) noexcept; // C++14 |
| 112 | template <class T1, class... T> |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 113 | constexpr const T1& get(const tuple<T...>&) noexcept; // C++14 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 114 | template <class T1, class... T> |
| 115 | constexpr T1&& get(tuple<T...>&&) noexcept; // C++14 |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 116 | template <class T1, class... T> |
| 117 | constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 118 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 119 | // 20.4.1.6, relational operators: |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 120 | template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
| 121 | template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
| 122 | template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
| 123 | template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
| 124 | template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
| 125 | template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | |
| 127 | template <class... Types, class Alloc> |
| 128 | struct uses_allocator<tuple<Types...>, Alloc>; |
| 129 | |
| 130 | template <class... Types> |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 131 | void |
| 132 | swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 133 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 134 | } // std |
| 135 | |
| 136 | */ |
| 137 | |
| 138 | #include <__config> |
| 139 | #include <__tuple> |
| 140 | #include <cstddef> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 141 | #include <type_traits> |
Howard Hinnant | 6cc99fa | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 142 | #include <__functional_base> |
| 143 | #include <utility> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 145 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 146 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 147 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 148 | |
| 149 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 150 | |
| 151 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 152 | |
| 153 | // tuple_size |
| 154 | |
| 155 | template <class ..._Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 156 | class _LIBCPP_TYPE_VIS_ONLY tuple_size<tuple<_Tp...> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 157 | : public integral_constant<size_t, sizeof...(_Tp)> |
| 158 | { |
| 159 | }; |
| 160 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 161 | // tuple_element |
| 162 | |
| 163 | template <size_t _Ip, class ..._Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 164 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, tuple<_Tp...> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 165 | { |
| 166 | public: |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 167 | typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
Marshall Clow | 50fe0c7 | 2014-03-03 06:18:11 +0000 | [diff] [blame] | 170 | #if _LIBCPP_STD_VER > 11 |
| 171 | template <size_t _Ip, class ..._Tp> |
| 172 | using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; |
| 173 | #endif |
| 174 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 175 | // __tuple_leaf |
| 176 | |
Eric Fiselier | 3a0e430 | 2015-06-13 07:08:02 +0000 | [diff] [blame] | 177 | template <size_t _Ip, class _Hp, |
| 178 | bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value |
Howard Hinnant | d4cf215 | 2011-12-11 20:31:33 +0000 | [diff] [blame] | 179 | > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 180 | class __tuple_leaf; |
| 181 | |
| 182 | template <size_t _Ip, class _Hp, bool _Ep> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 183 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 184 | void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 185 | _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | { |
| 187 | swap(__x.get(), __y.get()); |
| 188 | } |
| 189 | |
| 190 | template <size_t _Ip, class _Hp, bool> |
| 191 | class __tuple_leaf |
| 192 | { |
| 193 | _Hp value; |
| 194 | |
| 195 | __tuple_leaf& operator=(const __tuple_leaf&); |
| 196 | public: |
Howard Hinnant | 4eebfc3 | 2012-07-06 20:50:27 +0000 | [diff] [blame] | 197 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf() |
| 198 | _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 199 | {static_assert(!is_reference<_Hp>::value, |
| 200 | "Attempted to default construct a reference element in a tuple");} |
| 201 | |
| 202 | template <class _Alloc> |
| 203 | _LIBCPP_INLINE_VISIBILITY |
| 204 | __tuple_leaf(integral_constant<int, 0>, const _Alloc&) |
| 205 | : value() |
| 206 | {static_assert(!is_reference<_Hp>::value, |
| 207 | "Attempted to default construct a reference element in a tuple");} |
| 208 | |
| 209 | template <class _Alloc> |
| 210 | _LIBCPP_INLINE_VISIBILITY |
| 211 | __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) |
| 212 | : value(allocator_arg_t(), __a) |
| 213 | {static_assert(!is_reference<_Hp>::value, |
| 214 | "Attempted to default construct a reference element in a tuple");} |
| 215 | |
| 216 | template <class _Alloc> |
| 217 | _LIBCPP_INLINE_VISIBILITY |
| 218 | __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) |
| 219 | : value(__a) |
| 220 | {static_assert(!is_reference<_Hp>::value, |
| 221 | "Attempted to default construct a reference element in a tuple");} |
| 222 | |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame] | 223 | template <class _Tp, |
Eric Fiselier | 9020c08 | 2014-07-24 18:48:34 +0000 | [diff] [blame] | 224 | class = typename enable_if< |
| 225 | __lazy_and< |
| 226 | __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>> |
| 227 | , is_constructible<_Hp, _Tp> |
| 228 | >::value |
| 229 | >::type |
| 230 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 231 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 232 | explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 233 | : value(_VSTD::forward<_Tp>(__t)) |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame] | 234 | {static_assert(!is_reference<_Hp>::value || |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 235 | (is_lvalue_reference<_Hp>::value && |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 236 | (is_lvalue_reference<_Tp>::value || |
| 237 | is_same<typename remove_reference<_Tp>::type, |
| 238 | reference_wrapper< |
| 239 | typename remove_reference<_Hp>::type |
| 240 | > |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 241 | >::value)) || |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame] | 242 | (is_rvalue_reference<_Hp>::value && |
| 243 | !is_lvalue_reference<_Tp>::value), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 244 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 245 | |
| 246 | template <class _Tp, class _Alloc> |
| 247 | _LIBCPP_INLINE_VISIBILITY |
| 248 | explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 249 | : value(_VSTD::forward<_Tp>(__t)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | {static_assert(!is_lvalue_reference<_Hp>::value || |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 251 | (is_lvalue_reference<_Hp>::value && |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 252 | (is_lvalue_reference<_Tp>::value || |
| 253 | is_same<typename remove_reference<_Tp>::type, |
| 254 | reference_wrapper< |
| 255 | typename remove_reference<_Hp>::type |
| 256 | > |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 257 | >::value)), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 258 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 259 | |
| 260 | template <class _Tp, class _Alloc> |
| 261 | _LIBCPP_INLINE_VISIBILITY |
| 262 | explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 263 | : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 264 | {static_assert(!is_lvalue_reference<_Hp>::value || |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 265 | (is_lvalue_reference<_Hp>::value && |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 266 | (is_lvalue_reference<_Tp>::value || |
| 267 | is_same<typename remove_reference<_Tp>::type, |
| 268 | reference_wrapper< |
| 269 | typename remove_reference<_Hp>::type |
| 270 | > |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 271 | >::value)), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 272 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 273 | |
| 274 | template <class _Tp, class _Alloc> |
| 275 | _LIBCPP_INLINE_VISIBILITY |
| 276 | explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 277 | : value(_VSTD::forward<_Tp>(__t), __a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | {static_assert(!is_lvalue_reference<_Hp>::value || |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 279 | (is_lvalue_reference<_Hp>::value && |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 280 | (is_lvalue_reference<_Tp>::value || |
| 281 | is_same<typename remove_reference<_Tp>::type, |
| 282 | reference_wrapper< |
| 283 | typename remove_reference<_Hp>::type |
| 284 | > |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 285 | >::value)), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 286 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 287 | |
Marshall Clow | 398c9d8 | 2014-04-21 23:48:09 +0000 | [diff] [blame] | 288 | __tuple_leaf(const __tuple_leaf& __t) = default; |
| 289 | __tuple_leaf(__tuple_leaf&& __t) = default; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 290 | |
| 291 | template <class _Tp> |
| 292 | _LIBCPP_INLINE_VISIBILITY |
| 293 | __tuple_leaf& |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 294 | operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 295 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 296 | value = _VSTD::forward<_Tp>(__t); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 297 | return *this; |
| 298 | } |
| 299 | |
| 300 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 301 | int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 302 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 303 | _VSTD::swap(*this, __t); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 307 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;} |
| 308 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | }; |
| 310 | |
| 311 | template <size_t _Ip, class _Hp> |
| 312 | class __tuple_leaf<_Ip, _Hp, true> |
| 313 | : private _Hp |
| 314 | { |
| 315 | |
| 316 | __tuple_leaf& operator=(const __tuple_leaf&); |
| 317 | public: |
Howard Hinnant | 4eebfc3 | 2012-07-06 20:50:27 +0000 | [diff] [blame] | 318 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf() |
| 319 | _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 320 | |
| 321 | template <class _Alloc> |
| 322 | _LIBCPP_INLINE_VISIBILITY |
| 323 | __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {} |
| 324 | |
| 325 | template <class _Alloc> |
| 326 | _LIBCPP_INLINE_VISIBILITY |
| 327 | __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) |
| 328 | : _Hp(allocator_arg_t(), __a) {} |
| 329 | |
| 330 | template <class _Alloc> |
| 331 | _LIBCPP_INLINE_VISIBILITY |
| 332 | __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) |
| 333 | : _Hp(__a) {} |
| 334 | |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame] | 335 | template <class _Tp, |
Eric Fiselier | 9020c08 | 2014-07-24 18:48:34 +0000 | [diff] [blame] | 336 | class = typename enable_if< |
| 337 | __lazy_and< |
| 338 | __lazy_not<is_same<typename decay<_Tp>::type, __tuple_leaf>> |
| 339 | , is_constructible<_Hp, _Tp> |
| 340 | >::value |
| 341 | >::type |
| 342 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 343 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 344 | explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 345 | : _Hp(_VSTD::forward<_Tp>(__t)) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 346 | |
| 347 | template <class _Tp, class _Alloc> |
| 348 | _LIBCPP_INLINE_VISIBILITY |
| 349 | explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 350 | : _Hp(_VSTD::forward<_Tp>(__t)) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 351 | |
| 352 | template <class _Tp, class _Alloc> |
| 353 | _LIBCPP_INLINE_VISIBILITY |
| 354 | explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 355 | : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 356 | |
| 357 | template <class _Tp, class _Alloc> |
| 358 | _LIBCPP_INLINE_VISIBILITY |
| 359 | explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 360 | : _Hp(_VSTD::forward<_Tp>(__t), __a) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 361 | |
Eric Fiselier | 9020c08 | 2014-07-24 18:48:34 +0000 | [diff] [blame] | 362 | __tuple_leaf(__tuple_leaf const &) = default; |
| 363 | __tuple_leaf(__tuple_leaf &&) = default; |
| 364 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | template <class _Tp> |
| 366 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 367 | __tuple_leaf& |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 368 | operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 369 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 370 | _Hp::operator=(_VSTD::forward<_Tp>(__t)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 371 | return *this; |
| 372 | } |
| 373 | |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 374 | _LIBCPP_INLINE_VISIBILITY |
| 375 | int |
| 376 | swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 378 | _VSTD::swap(*this, __t); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 379 | return 0; |
| 380 | } |
| 381 | |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 382 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);} |
| 383 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | }; |
| 385 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 386 | template <class ..._Tp> |
| 387 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 388 | void __swallow(_Tp&&...) _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 389 | |
Eric Fiselier | 55ad3ac | 2016-04-15 03:29:40 +0000 | [diff] [blame] | 390 | template <class ..._Tp> |
| 391 | struct __lazy_all : __all<_Tp::value...> {}; |
| 392 | |
Marshall Clow | bbc7c74 | 2014-10-15 10:33:02 +0000 | [diff] [blame] | 393 | template <class _Tp> |
| 394 | struct __all_default_constructible; |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 395 | |
Marshall Clow | bbc7c74 | 2014-10-15 10:33:02 +0000 | [diff] [blame] | 396 | template <class ..._Tp> |
| 397 | struct __all_default_constructible<__tuple_types<_Tp...>> |
| 398 | : __all<is_default_constructible<_Tp>::value...> |
| 399 | { }; |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 400 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | // __tuple_impl |
| 402 | |
| 403 | template<class _Indx, class ..._Tp> struct __tuple_impl; |
| 404 | |
| 405 | template<size_t ..._Indx, class ..._Tp> |
| 406 | struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> |
| 407 | : public __tuple_leaf<_Indx, _Tp>... |
| 408 | { |
Howard Hinnant | 5394c1e | 2012-07-06 20:39:45 +0000 | [diff] [blame] | 409 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4eebfc3 | 2012-07-06 20:50:27 +0000 | [diff] [blame] | 410 | _LIBCPP_CONSTEXPR __tuple_impl() |
| 411 | _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {} |
Howard Hinnant | 5394c1e | 2012-07-06 20:39:45 +0000 | [diff] [blame] | 412 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 413 | template <size_t ..._Uf, class ..._Tf, |
| 414 | size_t ..._Ul, class ..._Tl, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 415 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 416 | explicit |
| 417 | __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>, |
| 418 | __tuple_indices<_Ul...>, __tuple_types<_Tl...>, |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 419 | _Up&&... __u) |
| 420 | _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value && |
| 421 | __all<is_nothrow_default_constructible<_Tl>::value...>::value)) : |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 422 | __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))..., |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | __tuple_leaf<_Ul, _Tl>()... |
| 424 | {} |
| 425 | |
| 426 | template <class _Alloc, size_t ..._Uf, class ..._Tf, |
| 427 | size_t ..._Ul, class ..._Tl, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 428 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | explicit |
| 430 | __tuple_impl(allocator_arg_t, const _Alloc& __a, |
| 431 | __tuple_indices<_Uf...>, __tuple_types<_Tf...>, |
| 432 | __tuple_indices<_Ul...>, __tuple_types<_Tl...>, |
| 433 | _Up&&... __u) : |
| 434 | __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a, |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 435 | _VSTD::forward<_Up>(__u))..., |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 436 | __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)... |
| 437 | {} |
| 438 | |
| 439 | template <class _Tuple, |
| 440 | class = typename enable_if |
| 441 | < |
Howard Hinnant | 9932489 | 2013-04-14 00:01:13 +0000 | [diff] [blame] | 442 | __tuple_constructible<_Tuple, tuple<_Tp...> >::value |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 443 | >::type |
| 444 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 445 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 446 | __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx, |
| 447 | typename __make_tuple_types<_Tuple>::type>::type>::value...>::value)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 448 | : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx, |
| 449 | typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))... |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 450 | {} |
| 451 | |
| 452 | template <class _Alloc, class _Tuple, |
| 453 | class = typename enable_if |
| 454 | < |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 455 | __tuple_constructible<_Tuple, tuple<_Tp...> >::value |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 456 | >::type |
| 457 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 458 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 459 | __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) |
| 460 | : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx, |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 461 | typename __make_tuple_types<_Tuple>::type>::type>(), __a, |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 462 | _VSTD::forward<typename tuple_element<_Indx, |
| 463 | typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))... |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 464 | {} |
| 465 | |
| 466 | template <class _Tuple> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 467 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 468 | typename enable_if |
| 469 | < |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 470 | __tuple_assignable<_Tuple, tuple<_Tp...> >::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 471 | __tuple_impl& |
| 472 | >::type |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 473 | operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx, |
| 474 | typename __make_tuple_types<_Tuple>::type>::type>::value...>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 475 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 476 | __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx, |
| 477 | typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 478 | return *this; |
| 479 | } |
| 480 | |
Howard Hinnant | 3de5086 | 2013-11-06 17:45:43 +0000 | [diff] [blame] | 481 | __tuple_impl(const __tuple_impl&) = default; |
| 482 | __tuple_impl(__tuple_impl&&) = default; |
| 483 | |
| 484 | _LIBCPP_INLINE_VISIBILITY |
| 485 | __tuple_impl& |
| 486 | operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value)) |
| 487 | { |
| 488 | __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...); |
| 489 | return *this; |
| 490 | } |
| 491 | |
| 492 | _LIBCPP_INLINE_VISIBILITY |
| 493 | __tuple_impl& |
| 494 | operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value)) |
| 495 | { |
| 496 | __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...); |
| 497 | return *this; |
| 498 | } |
Howard Hinnant | 2848444 | 2012-02-15 20:13:52 +0000 | [diff] [blame] | 499 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 500 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 501 | void swap(__tuple_impl& __t) |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 502 | _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 503 | { |
| 504 | __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...); |
| 505 | } |
| 506 | }; |
| 507 | |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 508 | template <bool _IsTuple, class _SizeTrait, size_t _Expected> |
| 509 | struct __tuple_like_with_size_imp : false_type {}; |
| 510 | |
| 511 | template <class _SizeTrait, size_t _Expected> |
| 512 | struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected> |
| 513 | : integral_constant<bool, _SizeTrait::value == _Expected> {}; |
| 514 | |
| 515 | template <class _Tuple, size_t _ExpectedSize, |
| 516 | class _RawTuple = typename __uncvref<_Tuple>::type> |
| 517 | using __tuple_like_with_size = __tuple_like_with_size_imp< |
| 518 | __tuple_like<_RawTuple>::value, |
| 519 | tuple_size<_RawTuple>, _ExpectedSize |
| 520 | >; |
| 521 | |
| 522 | |
| 523 | struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail { |
| 524 | template <class ...> |
| 525 | static constexpr bool __enable_explicit() { return false; } |
| 526 | template <class ...> |
| 527 | static constexpr bool __enable_implicit() { return false; } |
| 528 | }; |
| 529 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 530 | template <class ..._Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 531 | class _LIBCPP_TYPE_VIS_ONLY tuple |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | { |
| 533 | typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base; |
| 534 | |
| 535 | base base_; |
| 536 | |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 537 | template <class ..._Args> |
| 538 | struct _PackExpandsToThisTuple : false_type {}; |
| 539 | |
| 540 | template <class _Arg> |
| 541 | struct _PackExpandsToThisTuple<_Arg> |
| 542 | : is_same<typename __uncvref<_Arg>::type, tuple> {}; |
| 543 | |
| 544 | template <bool _MaybeEnable, class _Dummy = void> |
| 545 | struct _CheckArgsConstructor : __check_tuple_constructor_fail {}; |
| 546 | |
| 547 | template <class _Dummy> |
| 548 | struct _CheckArgsConstructor<true, _Dummy> |
| 549 | { |
| 550 | template <class ..._Args> |
| 551 | static constexpr bool __enable_explicit() { |
| 552 | return |
| 553 | __tuple_constructible< |
| 554 | tuple<_Args...>, |
| 555 | typename __make_tuple_types<tuple, |
| 556 | sizeof...(_Args) < sizeof...(_Tp) ? |
| 557 | sizeof...(_Args) : |
| 558 | sizeof...(_Tp)>::type |
| 559 | >::value && |
| 560 | !__tuple_convertible< |
| 561 | tuple<_Args...>, |
| 562 | typename __make_tuple_types<tuple, |
| 563 | sizeof...(_Args) < sizeof...(_Tp) ? |
| 564 | sizeof...(_Args) : |
| 565 | sizeof...(_Tp)>::type |
| 566 | >::value && |
| 567 | __all_default_constructible< |
| 568 | typename __make_tuple_types<tuple, sizeof...(_Tp), |
| 569 | sizeof...(_Args) < sizeof...(_Tp) ? |
| 570 | sizeof...(_Args) : |
| 571 | sizeof...(_Tp)>::type |
| 572 | >::value; |
| 573 | } |
| 574 | |
| 575 | template <class ..._Args> |
| 576 | static constexpr bool __enable_implicit() { |
| 577 | return |
| 578 | __tuple_convertible< |
| 579 | tuple<_Args...>, |
| 580 | typename __make_tuple_types<tuple, |
| 581 | sizeof...(_Args) < sizeof...(_Tp) ? |
| 582 | sizeof...(_Args) : |
| 583 | sizeof...(_Tp)>::type |
| 584 | >::value && |
| 585 | __all_default_constructible< |
| 586 | typename __make_tuple_types<tuple, sizeof...(_Tp), |
| 587 | sizeof...(_Args) < sizeof...(_Tp) ? |
| 588 | sizeof...(_Args) : |
| 589 | sizeof...(_Tp)>::type |
| 590 | >::value; |
| 591 | } |
| 592 | }; |
| 593 | |
| 594 | template <bool _MaybeEnable, |
| 595 | bool = sizeof...(_Tp) == 1, |
| 596 | class _Dummy = void> |
| 597 | struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {}; |
| 598 | |
| 599 | template <class _Dummy> |
| 600 | struct _CheckTupleLikeConstructor<true, false, _Dummy> |
| 601 | { |
| 602 | template <class _Tuple> |
| 603 | static constexpr bool __enable_implicit() { |
| 604 | return __tuple_convertible<_Tuple, tuple>::value; |
| 605 | } |
| 606 | |
| 607 | template <class _Tuple> |
| 608 | static constexpr bool __enable_explicit() { |
| 609 | return __tuple_constructible<_Tuple, tuple>::value |
| 610 | && !__tuple_convertible<_Tuple, tuple>::value; |
| 611 | } |
| 612 | }; |
| 613 | |
| 614 | template <class _Dummy> |
| 615 | struct _CheckTupleLikeConstructor<true, true, _Dummy> |
| 616 | { |
| 617 | // This trait is used to disable the tuple-like constructor when |
| 618 | // the UTypes... constructor should be selected instead. |
| 619 | // See LWG issue #2549. |
| 620 | template <class _Tuple> |
| 621 | using _PreferTupleLikeConstructor = __lazy_or< |
| 622 | // Don't attempt the two checks below if the tuple we are given |
| 623 | // has the same type as this tuple. |
| 624 | is_same<typename __uncvref<_Tuple>::type, tuple>, |
| 625 | __lazy_and< |
| 626 | __lazy_not<is_constructible<_Tp..., _Tuple>>, |
| 627 | __lazy_not<is_convertible<_Tuple, _Tp...>> |
| 628 | > |
| 629 | >; |
| 630 | |
| 631 | template <class _Tuple> |
| 632 | static constexpr bool __enable_implicit() { |
| 633 | return __lazy_and< |
| 634 | __tuple_convertible<_Tuple, tuple>, |
| 635 | _PreferTupleLikeConstructor<_Tuple> |
| 636 | >::value; |
| 637 | } |
| 638 | |
| 639 | template <class _Tuple> |
| 640 | static constexpr bool __enable_explicit() { |
| 641 | return __lazy_and< |
| 642 | __tuple_constructible<_Tuple, tuple>, |
| 643 | _PreferTupleLikeConstructor<_Tuple>, |
| 644 | __lazy_not<__tuple_convertible<_Tuple, tuple>> |
| 645 | >::value; |
| 646 | } |
| 647 | }; |
| 648 | |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 649 | template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 650 | typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT; |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 651 | template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 652 | const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT; |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 653 | template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 654 | typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT; |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 655 | template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 656 | const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 657 | public: |
| 658 | |
Eric Fiselier | da1818a | 2015-02-21 02:30:41 +0000 | [diff] [blame] | 659 | template <bool _Dummy = true, class = typename enable_if< |
| 660 | __all<__dependent_type<is_default_constructible<_Tp>, _Dummy>::value...>::value |
Marshall Clow | bbc7c74 | 2014-10-15 10:33:02 +0000 | [diff] [blame] | 661 | >::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 662 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4eebfc3 | 2012-07-06 20:50:27 +0000 | [diff] [blame] | 663 | _LIBCPP_CONSTEXPR tuple() |
| 664 | _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {} |
Howard Hinnant | 5394c1e | 2012-07-06 20:39:45 +0000 | [diff] [blame] | 665 | |
Eric Fiselier | 55ad3ac | 2016-04-15 03:29:40 +0000 | [diff] [blame] | 666 | template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if< |
| 667 | __lazy_and< |
Eric Fiselier | fa5a105 | 2016-06-21 23:19:13 +0000 | [diff] [blame] | 668 | is_same<allocator_arg_t, _AllocArgT>, |
Eric Fiselier | 55ad3ac | 2016-04-15 03:29:40 +0000 | [diff] [blame] | 669 | __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...> |
| 670 | >::value |
| 671 | >::type> |
| 672 | _LIBCPP_INLINE_VISIBILITY |
| 673 | tuple(_AllocArgT, _Alloc const& __a) |
| 674 | : base_(allocator_arg_t(), __a, |
| 675 | __tuple_indices<>(), __tuple_types<>(), |
| 676 | typename __make_tuple_indices<sizeof...(_Tp), 0>::type(), |
| 677 | __tuple_types<_Tp...>()) {} |
| 678 | |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 679 | template <bool _Dummy = true, |
| 680 | typename enable_if |
| 681 | < |
| 682 | _CheckArgsConstructor< |
| 683 | _Dummy |
| 684 | >::template __enable_implicit<_Tp...>(), |
| 685 | bool |
| 686 | >::type = false |
| 687 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 688 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 689 | tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 690 | : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 691 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 692 | typename __make_tuple_indices<0>::type(), |
| 693 | typename __make_tuple_types<tuple, 0>::type(), |
| 694 | __t... |
| 695 | ) {} |
| 696 | |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 697 | template <bool _Dummy = true, |
| 698 | typename enable_if |
| 699 | < |
| 700 | _CheckArgsConstructor< |
| 701 | _Dummy |
| 702 | >::template __enable_explicit<_Tp...>(), |
| 703 | bool |
| 704 | >::type = false |
| 705 | > |
| 706 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 707 | explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) |
| 708 | : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 709 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 710 | typename __make_tuple_indices<0>::type(), |
| 711 | typename __make_tuple_types<tuple, 0>::type(), |
| 712 | __t... |
| 713 | ) {} |
| 714 | |
| 715 | template <class _Alloc, bool _Dummy = true, |
| 716 | typename enable_if |
| 717 | < |
| 718 | _CheckArgsConstructor< |
| 719 | _Dummy |
| 720 | >::template __enable_implicit<_Tp...>(), |
| 721 | bool |
| 722 | >::type = false |
| 723 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 724 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 725 | tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) |
| 726 | : base_(allocator_arg_t(), __a, |
| 727 | typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 728 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 729 | typename __make_tuple_indices<0>::type(), |
| 730 | typename __make_tuple_types<tuple, 0>::type(), |
| 731 | __t... |
| 732 | ) {} |
| 733 | |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 734 | template <class _Alloc, bool _Dummy = true, |
| 735 | typename enable_if |
| 736 | < |
| 737 | _CheckArgsConstructor< |
| 738 | _Dummy |
| 739 | >::template __enable_explicit<_Tp...>(), |
| 740 | bool |
| 741 | >::type = false |
| 742 | > |
| 743 | _LIBCPP_INLINE_VISIBILITY |
| 744 | explicit |
| 745 | tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) |
| 746 | : base_(allocator_arg_t(), __a, |
| 747 | typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 748 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 749 | typename __make_tuple_indices<0>::type(), |
| 750 | typename __make_tuple_types<tuple, 0>::type(), |
| 751 | __t... |
| 752 | ) {} |
| 753 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 754 | template <class ..._Up, |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 755 | typename enable_if |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 756 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 757 | _CheckArgsConstructor< |
| 758 | sizeof...(_Up) <= sizeof...(_Tp) |
| 759 | && !_PackExpandsToThisTuple<_Up...>::value |
| 760 | >::template __enable_implicit<_Up...>(), |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 761 | bool |
| 762 | >::type = false |
| 763 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 764 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 765 | tuple(_Up&&... __u) |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 766 | _NOEXCEPT_(( |
Marshall Clow | 86d311c | 2014-09-16 17:08:21 +0000 | [diff] [blame] | 767 | is_nothrow_constructible<base, |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 768 | typename __make_tuple_indices<sizeof...(_Up)>::type, |
| 769 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type, |
| 770 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type, |
| 771 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type, |
Marshall Clow | 86d311c | 2014-09-16 17:08:21 +0000 | [diff] [blame] | 772 | _Up... |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 773 | >::value |
| 774 | )) |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 775 | : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 776 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 777 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 778 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 779 | _VSTD::forward<_Up>(__u)...) {} |
| 780 | |
| 781 | template <class ..._Up, |
| 782 | typename enable_if |
| 783 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 784 | _CheckArgsConstructor< |
| 785 | sizeof...(_Up) <= sizeof...(_Tp) |
| 786 | && !_PackExpandsToThisTuple<_Up...>::value |
| 787 | >::template __enable_explicit<_Up...>(), |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 788 | bool |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 789 | >::type = false |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 790 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 791 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 792 | explicit |
| 793 | tuple(_Up&&... __u) |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 794 | _NOEXCEPT_(( |
Marshall Clow | 86d311c | 2014-09-16 17:08:21 +0000 | [diff] [blame] | 795 | is_nothrow_constructible<base, |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 796 | typename __make_tuple_indices<sizeof...(_Up)>::type, |
| 797 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type, |
| 798 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type, |
| 799 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type, |
| 800 | _Up... |
| 801 | >::value |
| 802 | )) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 803 | : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 804 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 805 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 806 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 807 | _VSTD::forward<_Up>(__u)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 808 | |
| 809 | template <class _Alloc, class ..._Up, |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 810 | typename enable_if |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 811 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 812 | _CheckArgsConstructor< |
| 813 | sizeof...(_Up) == sizeof...(_Tp) && |
| 814 | !_PackExpandsToThisTuple<_Up...>::value |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 815 | >::template __enable_implicit<_Up...>(), |
| 816 | bool |
| 817 | >::type = false |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 818 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 819 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 820 | tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) |
| 821 | : base_(allocator_arg_t(), __a, |
| 822 | typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 823 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 824 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 825 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 826 | _VSTD::forward<_Up>(__u)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 827 | |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 828 | template <class _Alloc, class ..._Up, |
| 829 | typename enable_if |
| 830 | < |
| 831 | _CheckArgsConstructor< |
| 832 | sizeof...(_Up) == sizeof...(_Tp) && |
| 833 | !_PackExpandsToThisTuple<_Up...>::value |
| 834 | >::template __enable_explicit<_Up...>(), |
| 835 | bool |
| 836 | >::type = false |
| 837 | > |
| 838 | _LIBCPP_INLINE_VISIBILITY |
| 839 | explicit |
| 840 | tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) |
| 841 | : base_(allocator_arg_t(), __a, |
| 842 | typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 843 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 844 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 845 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 846 | _VSTD::forward<_Up>(__u)...) {} |
| 847 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 848 | template <class _Tuple, |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 849 | typename enable_if |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 850 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 851 | _CheckTupleLikeConstructor< |
| 852 | __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value |
| 853 | && !_PackExpandsToThisTuple<_Tuple>::value |
| 854 | >::template __enable_implicit<_Tuple>(), |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 855 | bool |
| 856 | >::type = false |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 857 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 858 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 859 | tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 860 | : base_(_VSTD::forward<_Tuple>(__t)) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 861 | |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 862 | template <class _Tuple, |
| 863 | typename enable_if |
| 864 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 865 | _CheckTupleLikeConstructor< |
| 866 | __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value |
| 867 | && !_PackExpandsToThisTuple<_Tuple>::value |
| 868 | >::template __enable_explicit<_Tuple>(), |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 869 | bool |
| 870 | >::type = false |
| 871 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 872 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 873 | explicit |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 874 | tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value)) |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 875 | : base_(_VSTD::forward<_Tuple>(__t)) {} |
| 876 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 877 | template <class _Alloc, class _Tuple, |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 878 | typename enable_if |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 879 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 880 | _CheckTupleLikeConstructor< |
| 881 | __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 882 | >::template __enable_implicit<_Tuple>(), |
| 883 | bool |
| 884 | >::type = false |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 885 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 886 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 887 | tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 888 | : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 889 | |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 890 | template <class _Alloc, class _Tuple, |
| 891 | typename enable_if |
| 892 | < |
| 893 | _CheckTupleLikeConstructor< |
| 894 | __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value |
| 895 | >::template __enable_explicit<_Tuple>(), |
| 896 | bool |
| 897 | >::type = false |
| 898 | > |
| 899 | _LIBCPP_INLINE_VISIBILITY |
| 900 | explicit |
| 901 | tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) |
| 902 | : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} |
| 903 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 904 | template <class _Tuple, |
| 905 | class = typename enable_if |
| 906 | < |
| 907 | __tuple_assignable<_Tuple, tuple>::value |
| 908 | >::type |
| 909 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 910 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 911 | tuple& |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 912 | operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 913 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 914 | base_.operator=(_VSTD::forward<_Tuple>(__t)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 915 | return *this; |
| 916 | } |
| 917 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 918 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 919 | void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) |
| 920 | {base_.swap(__t.base_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 921 | }; |
| 922 | |
| 923 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 924 | class _LIBCPP_TYPE_VIS_ONLY tuple<> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 925 | { |
| 926 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 927 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4eebfc3 | 2012-07-06 20:50:27 +0000 | [diff] [blame] | 928 | _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 929 | template <class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 930 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 931 | tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 932 | template <class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 933 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 934 | tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 935 | template <class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 936 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 937 | tuple(array<_Up, 0>) _NOEXCEPT {} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 938 | template <class _Alloc, class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 939 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 940 | tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 941 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 942 | void swap(tuple&) _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 943 | }; |
| 944 | |
| 945 | template <class ..._Tp> |
| 946 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aabf287 | 2011-06-01 19:59:32 +0000 | [diff] [blame] | 947 | typename enable_if |
| 948 | < |
| 949 | __all<__is_swappable<_Tp>::value...>::value, |
| 950 | void |
| 951 | >::type |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 952 | swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) |
| 953 | _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) |
| 954 | {__t.swap(__u);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 955 | |
| 956 | // get |
| 957 | |
| 958 | template <size_t _Ip, class ..._Tp> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 959 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 960 | typename tuple_element<_Ip, tuple<_Tp...> >::type& |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 961 | get(tuple<_Tp...>& __t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 962 | { |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 963 | typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 964 | return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get(); |
| 965 | } |
| 966 | |
| 967 | template <size_t _Ip, class ..._Tp> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 968 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 969 | const typename tuple_element<_Ip, tuple<_Tp...> >::type& |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 970 | get(const tuple<_Tp...>& __t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 971 | { |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 972 | typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 973 | return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get(); |
| 974 | } |
| 975 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 976 | template <size_t _Ip, class ..._Tp> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 977 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 978 | typename tuple_element<_Ip, tuple<_Tp...> >::type&& |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 979 | get(tuple<_Tp...>&& __t) _NOEXCEPT |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 980 | { |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 981 | typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; |
Howard Hinnant | 56a85ca | 2011-01-25 16:31:30 +0000 | [diff] [blame] | 982 | return static_cast<type&&>( |
Douglas Gregor | 6c66994 | 2011-01-25 16:14:21 +0000 | [diff] [blame] | 983 | static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get()); |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 986 | template <size_t _Ip, class ..._Tp> |
| 987 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 988 | const typename tuple_element<_Ip, tuple<_Tp...> >::type&& |
| 989 | get(const tuple<_Tp...>&& __t) _NOEXCEPT |
| 990 | { |
| 991 | typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; |
| 992 | return static_cast<const type&&>( |
| 993 | static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get()); |
| 994 | } |
| 995 | |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 996 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 997 | |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 998 | namespace __find_detail { |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 999 | |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1000 | static constexpr size_t __not_found = -1; |
| 1001 | static constexpr size_t __ambiguous = __not_found - 1; |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1002 | |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1003 | inline _LIBCPP_INLINE_VISIBILITY |
| 1004 | constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) { |
| 1005 | return !__matches ? __res : |
| 1006 | (__res == __not_found ? __curr_i : __ambiguous); |
| 1007 | } |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1008 | |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1009 | template <size_t _Nx> |
| 1010 | inline _LIBCPP_INLINE_VISIBILITY |
| 1011 | constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) { |
| 1012 | return __i == _Nx ? __not_found : |
| 1013 | __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]); |
| 1014 | } |
| 1015 | |
| 1016 | template <class _T1, class ..._Args> |
| 1017 | struct __find_exactly_one_checked { |
| 1018 | static constexpr bool __matches[] = {is_same<_T1, _Args>::value...}; |
| 1019 | static constexpr size_t value = __find_detail::__find_idx(0, __matches); |
| 1020 | static_assert (value != __not_found, "type not found in type list" ); |
| 1021 | static_assert(value != __ambiguous,"type occurs more than once in type list"); |
| 1022 | }; |
| 1023 | |
Eric Fiselier | 990090f | 2016-07-02 03:46:08 +0000 | [diff] [blame] | 1024 | template <class _T1> |
| 1025 | struct __find_exactly_one_checked<_T1> { |
| 1026 | static_assert(!is_same<_T1, _T1>::value, "type not in empty type list"); |
| 1027 | }; |
| 1028 | |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1029 | } // namespace __find_detail; |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1030 | |
| 1031 | template <typename _T1, typename... _Args> |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1032 | struct __find_exactly_one_t |
| 1033 | : public __find_detail::__find_exactly_one_checked<_T1, _Args...> { |
| 1034 | }; |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1035 | |
| 1036 | template <class _T1, class... _Args> |
| 1037 | inline _LIBCPP_INLINE_VISIBILITY |
| 1038 | constexpr _T1& get(tuple<_Args...>& __tup) noexcept |
| 1039 | { |
| 1040 | return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); |
| 1041 | } |
| 1042 | |
| 1043 | template <class _T1, class... _Args> |
| 1044 | inline _LIBCPP_INLINE_VISIBILITY |
| 1045 | constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept |
| 1046 | { |
| 1047 | return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); |
| 1048 | } |
| 1049 | |
| 1050 | template <class _T1, class... _Args> |
| 1051 | inline _LIBCPP_INLINE_VISIBILITY |
| 1052 | constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept |
| 1053 | { |
Marshall Clow | 01a0e90 | 2013-07-15 20:46:11 +0000 | [diff] [blame] | 1054 | return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup)); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 1057 | template <class _T1, class... _Args> |
| 1058 | inline _LIBCPP_INLINE_VISIBILITY |
| 1059 | constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept |
| 1060 | { |
| 1061 | return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup)); |
| 1062 | } |
| 1063 | |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1064 | #endif |
| 1065 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1066 | // tie |
| 1067 | |
| 1068 | template <class ..._Tp> |
Marshall Clow | 8e554d9 | 2014-02-25 16:11:46 +0000 | [diff] [blame] | 1069 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1070 | tuple<_Tp&...> |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 1071 | tie(_Tp&... __t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1072 | { |
| 1073 | return tuple<_Tp&...>(__t...); |
| 1074 | } |
| 1075 | |
| 1076 | template <class _Up> |
| 1077 | struct __ignore_t |
| 1078 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1079 | template <class _Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1080 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1081 | const __ignore_t& operator=(_Tp&&) const {return *this;} |
| 1082 | }; |
| 1083 | |
| 1084 | namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); } |
| 1085 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1086 | template <class _Tp> |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 1087 | struct __make_tuple_return_impl |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1088 | { |
| 1089 | typedef _Tp type; |
| 1090 | }; |
| 1091 | |
| 1092 | template <class _Tp> |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 1093 | struct __make_tuple_return_impl<reference_wrapper<_Tp> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1094 | { |
| 1095 | typedef _Tp& type; |
| 1096 | }; |
| 1097 | |
| 1098 | template <class _Tp> |
| 1099 | struct __make_tuple_return |
| 1100 | { |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 1101 | typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1102 | }; |
| 1103 | |
| 1104 | template <class... _Tp> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1105 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1106 | tuple<typename __make_tuple_return<_Tp>::type...> |
| 1107 | make_tuple(_Tp&&... __t) |
| 1108 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1109 | return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 1112 | template <class... _Tp> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1113 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 1114 | tuple<_Tp&&...> |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 1115 | forward_as_tuple(_Tp&&... __t) _NOEXCEPT |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 1116 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1117 | return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...); |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1120 | template <size_t _Ip> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1121 | struct __tuple_equal |
| 1122 | { |
| 1123 | template <class _Tp, class _Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1124 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1125 | bool operator()(const _Tp& __x, const _Up& __y) |
| 1126 | { |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1127 | return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1128 | } |
| 1129 | }; |
| 1130 | |
| 1131 | template <> |
| 1132 | struct __tuple_equal<0> |
| 1133 | { |
| 1134 | template <class _Tp, class _Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1135 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1136 | bool operator()(const _Tp&, const _Up&) |
| 1137 | { |
| 1138 | return true; |
| 1139 | } |
| 1140 | }; |
| 1141 | |
| 1142 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1143 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1144 | bool |
| 1145 | operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1146 | { |
| 1147 | return __tuple_equal<sizeof...(_Tp)>()(__x, __y); |
| 1148 | } |
| 1149 | |
| 1150 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1151 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1152 | bool |
| 1153 | operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1154 | { |
| 1155 | return !(__x == __y); |
| 1156 | } |
| 1157 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1158 | template <size_t _Ip> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1159 | struct __tuple_less |
| 1160 | { |
| 1161 | template <class _Tp, class _Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1162 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1163 | bool operator()(const _Tp& __x, const _Up& __y) |
| 1164 | { |
Duncan P. N. Exon Smith | 07b133f | 2015-01-21 02:51:17 +0000 | [diff] [blame] | 1165 | const size_t __idx = tuple_size<_Tp>::value - _Ip; |
| 1166 | if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y)) |
| 1167 | return true; |
| 1168 | if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x)) |
| 1169 | return false; |
| 1170 | return __tuple_less<_Ip-1>()(__x, __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1171 | } |
| 1172 | }; |
| 1173 | |
| 1174 | template <> |
| 1175 | struct __tuple_less<0> |
| 1176 | { |
| 1177 | template <class _Tp, class _Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1178 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1179 | bool operator()(const _Tp&, const _Up&) |
| 1180 | { |
| 1181 | return false; |
| 1182 | } |
| 1183 | }; |
| 1184 | |
| 1185 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1186 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1187 | bool |
| 1188 | operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1189 | { |
| 1190 | return __tuple_less<sizeof...(_Tp)>()(__x, __y); |
| 1191 | } |
| 1192 | |
| 1193 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1194 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1195 | bool |
| 1196 | operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1197 | { |
| 1198 | return __y < __x; |
| 1199 | } |
| 1200 | |
| 1201 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1202 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1203 | bool |
| 1204 | operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1205 | { |
| 1206 | return !(__x < __y); |
| 1207 | } |
| 1208 | |
| 1209 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1210 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1211 | bool |
| 1212 | operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1213 | { |
| 1214 | return !(__y < __x); |
| 1215 | } |
| 1216 | |
| 1217 | // tuple_cat |
| 1218 | |
Howard Hinnant | 0e1493e | 2010-12-11 20:47:50 +0000 | [diff] [blame] | 1219 | template <class _Tp, class _Up> struct __tuple_cat_type; |
| 1220 | |
| 1221 | template <class ..._Ttypes, class ..._Utypes> |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 1222 | struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1223 | { |
Howard Hinnant | 0e1493e | 2010-12-11 20:47:50 +0000 | [diff] [blame] | 1224 | typedef tuple<_Ttypes..., _Utypes...> type; |
| 1225 | }; |
| 1226 | |
| 1227 | template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples> |
| 1228 | struct __tuple_cat_return_1 |
| 1229 | { |
| 1230 | }; |
| 1231 | |
| 1232 | template <class ..._Types, class _Tuple0> |
| 1233 | struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0> |
| 1234 | { |
| 1235 | typedef typename __tuple_cat_type<tuple<_Types...>, |
| 1236 | typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type |
| 1237 | type; |
| 1238 | }; |
| 1239 | |
| 1240 | template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples> |
| 1241 | struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...> |
| 1242 | : public __tuple_cat_return_1< |
| 1243 | typename __tuple_cat_type< |
| 1244 | tuple<_Types...>, |
| 1245 | typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type |
| 1246 | >::type, |
| 1247 | __tuple_like<typename remove_reference<_Tuple1>::type>::value, |
| 1248 | _Tuple1, _Tuples...> |
| 1249 | { |
| 1250 | }; |
| 1251 | |
| 1252 | template <class ..._Tuples> struct __tuple_cat_return; |
| 1253 | |
| 1254 | template <class _Tuple0, class ..._Tuples> |
| 1255 | struct __tuple_cat_return<_Tuple0, _Tuples...> |
| 1256 | : public __tuple_cat_return_1<tuple<>, |
| 1257 | __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0, |
| 1258 | _Tuples...> |
| 1259 | { |
| 1260 | }; |
| 1261 | |
| 1262 | template <> |
| 1263 | struct __tuple_cat_return<> |
| 1264 | { |
| 1265 | typedef tuple<> type; |
| 1266 | }; |
| 1267 | |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1268 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 0e1493e | 2010-12-11 20:47:50 +0000 | [diff] [blame] | 1269 | tuple<> |
| 1270 | tuple_cat() |
| 1271 | { |
| 1272 | return tuple<>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1275 | template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples> |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1276 | struct __tuple_cat_return_ref_imp; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1277 | |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1278 | template <class ..._Types, size_t ..._I0, class _Tuple0> |
| 1279 | struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1280 | { |
Howard Hinnant | 0e1493e | 2010-12-11 20:47:50 +0000 | [diff] [blame] | 1281 | typedef typename remove_reference<_Tuple0>::type _T0; |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1282 | typedef tuple<_Types..., typename __apply_cv<_Tuple0, |
| 1283 | typename tuple_element<_I0, _T0>::type>::type&&...> type; |
| 1284 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1285 | |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1286 | template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples> |
| 1287 | struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, |
| 1288 | _Tuple0, _Tuple1, _Tuples...> |
| 1289 | : public __tuple_cat_return_ref_imp< |
| 1290 | tuple<_Types..., typename __apply_cv<_Tuple0, |
| 1291 | typename tuple_element<_I0, |
| 1292 | typename remove_reference<_Tuple0>::type>::type>::type&&...>, |
| 1293 | typename __make_tuple_indices<tuple_size<typename |
| 1294 | remove_reference<_Tuple1>::type>::value>::type, |
| 1295 | _Tuple1, _Tuples...> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1296 | { |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1297 | }; |
| 1298 | |
| 1299 | template <class _Tuple0, class ..._Tuples> |
| 1300 | struct __tuple_cat_return_ref |
| 1301 | : public __tuple_cat_return_ref_imp<tuple<>, |
| 1302 | typename __make_tuple_indices< |
| 1303 | tuple_size<typename remove_reference<_Tuple0>::type>::value |
| 1304 | >::type, _Tuple0, _Tuples...> |
| 1305 | { |
| 1306 | }; |
| 1307 | |
| 1308 | template <class _Types, class _I0, class _J0> |
| 1309 | struct __tuple_cat; |
| 1310 | |
| 1311 | template <class ..._Types, size_t ..._I0, size_t ..._J0> |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 1312 | struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> > |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1313 | { |
| 1314 | template <class _Tuple0> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1315 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1316 | typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type |
| 1317 | operator()(tuple<_Types...> __t, _Tuple0&& __t0) |
| 1318 | { |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1319 | return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))..., |
| 1320 | _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...); |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | template <class _Tuple0, class _Tuple1, class ..._Tuples> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1324 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1325 | typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type |
| 1326 | operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls) |
| 1327 | { |
| 1328 | typedef typename remove_reference<_Tuple0>::type _T0; |
| 1329 | typedef typename remove_reference<_Tuple1>::type _T1; |
| 1330 | return __tuple_cat< |
| 1331 | tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>, |
| 1332 | typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type, |
| 1333 | typename __make_tuple_indices<tuple_size<_T1>::value>::type>() |
Marshall Clow | 1d927e3 | 2013-10-05 18:46:37 +0000 | [diff] [blame] | 1334 | (forward_as_tuple( |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1335 | _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))..., |
| 1336 | _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))... |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1337 | ), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1338 | _VSTD::forward<_Tuple1>(__t1), |
| 1339 | _VSTD::forward<_Tuples>(__tpls)...); |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1340 | } |
| 1341 | }; |
| 1342 | |
| 1343 | template <class _Tuple0, class... _Tuples> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1344 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1345 | typename __tuple_cat_return<_Tuple0, _Tuples...>::type |
| 1346 | tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) |
| 1347 | { |
| 1348 | typedef typename remove_reference<_Tuple0>::type _T0; |
| 1349 | return __tuple_cat<tuple<>, __tuple_indices<>, |
| 1350 | typename __make_tuple_indices<tuple_size<_T0>::value>::type>() |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1351 | (tuple<>(), _VSTD::forward<_Tuple0>(__t0), |
| 1352 | _VSTD::forward<_Tuples>(__tpls)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | template <class ..._Tp, class _Alloc> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1356 | struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1357 | : true_type {}; |
| 1358 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1359 | template <class _T1, class _T2> |
| 1360 | template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2> |
| 1361 | inline _LIBCPP_INLINE_VISIBILITY |
| 1362 | pair<_T1, _T2>::pair(piecewise_construct_t, |
| 1363 | tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, |
| 1364 | __tuple_indices<_I1...>, __tuple_indices<_I2...>) |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1365 | : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...), |
| 1366 | second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1367 | { |
| 1368 | } |
| 1369 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1370 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1371 | |
Eric Fiselier | 5839fed | 2016-07-18 00:35:56 +0000 | [diff] [blame^] | 1372 | #if _LIBCPP_STD_VER > 14 |
| 1373 | template <class _Tp> |
| 1374 | constexpr size_t tuple_size_v = tuple_size<_Tp>::value; |
| 1375 | |
| 1376 | #define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } |
| 1377 | |
| 1378 | template <class _Fn, class _Tuple, size_t ..._Id> |
| 1379 | inline _LIBCPP_INLINE_VISIBILITY |
| 1380 | constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t, |
| 1381 | __tuple_indices<_Id...>) |
| 1382 | _LIBCPP_NOEXCEPT_RETURN( |
| 1383 | _VSTD::__invoke_constexpr( |
| 1384 | _VSTD::forward<_Fn>(__f), |
| 1385 | _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...) |
| 1386 | ) |
| 1387 | |
| 1388 | template <class _Fn, class _Tuple> |
| 1389 | inline _LIBCPP_INLINE_VISIBILITY |
| 1390 | constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t) |
| 1391 | _LIBCPP_NOEXCEPT_RETURN( |
| 1392 | _VSTD::__apply_tuple_impl( |
| 1393 | _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t), |
| 1394 | typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{}) |
| 1395 | ) |
| 1396 | |
| 1397 | template <class _Tp, class _Tuple, size_t... _Idx> |
| 1398 | inline _LIBCPP_INLINE_VISIBILITY |
| 1399 | constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>) |
| 1400 | _LIBCPP_NOEXCEPT_RETURN( |
| 1401 | _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...) |
| 1402 | ) |
| 1403 | |
| 1404 | template <class _Tp, class _Tuple> |
| 1405 | inline _LIBCPP_INLINE_VISIBILITY |
| 1406 | constexpr _Tp make_from_tuple(_Tuple&& __t) |
| 1407 | _LIBCPP_NOEXCEPT_RETURN( |
| 1408 | _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t), |
| 1409 | typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{}) |
| 1410 | ) |
| 1411 | |
| 1412 | #undef _LIBCPP_NOEXCEPT_RETURN |
| 1413 | |
| 1414 | #endif // _LIBCPP_STD_VER > 14 |
| 1415 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1416 | _LIBCPP_END_NAMESPACE_STD |
| 1417 | |
| 1418 | #endif // _LIBCPP_TUPLE |