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