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