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