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