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