Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- tuple ------------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_TUPLE |
| 12 | #define _LIBCPP_TUPLE |
| 13 | |
| 14 | /* |
| 15 | tuple synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class... T> |
| 21 | class tuple { |
| 22 | public: |
| 23 | constexpr tuple(); |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 24 | explicit tuple(const T&...); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 25 | template <class... U> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 26 | explicit tuple(U&&...); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 27 | tuple(const tuple&) = default; |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 28 | tuple(tuple&&) = default; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 29 | template <class... U> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 30 | tuple(const tuple<U...>&); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | template <class... U> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 32 | tuple(tuple<U...>&&); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | template <class U1, class U2> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 34 | tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | template <class U1, class U2> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 36 | tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 37 | |
| 38 | // allocator-extended constructors |
| 39 | template <class Alloc> |
| 40 | tuple(allocator_arg_t, const Alloc& a); |
| 41 | template <class Alloc> |
| 42 | tuple(allocator_arg_t, const Alloc& a, const T&...); |
| 43 | template <class Alloc, class... U> |
| 44 | tuple(allocator_arg_t, const Alloc& a, U&&...); |
| 45 | template <class Alloc> |
| 46 | tuple(allocator_arg_t, const Alloc& a, const tuple&); |
| 47 | template <class Alloc> |
| 48 | tuple(allocator_arg_t, const Alloc& a, tuple&&); |
| 49 | template <class Alloc, class... U> |
| 50 | tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); |
| 51 | template <class Alloc, class... U> |
| 52 | tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); |
| 53 | template <class Alloc, class U1, class U2> |
| 54 | tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); |
| 55 | template <class Alloc, class U1, class U2> |
| 56 | tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); |
| 57 | |
| 58 | tuple& operator=(const tuple&); |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 59 | tuple& |
| 60 | operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 61 | template <class... U> |
| 62 | tuple& operator=(const tuple<U...>&); |
| 63 | template <class... U> |
| 64 | tuple& operator=(tuple<U...>&&); |
| 65 | template <class U1, class U2> |
| 66 | tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 |
| 67 | template <class U1, class U2> |
| 68 | tuple& operator=(pair<U1, U2>&&); //iffsizeof...(T) == 2 |
| 69 | |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 70 | void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | const unspecified ignore; |
| 74 | |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 75 | template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14 |
Marshall Clow | 1d927e3 | 2013-10-05 18:46:37 +0000 | [diff] [blame] | 76 | template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14 |
Marshall Clow | 8e554d9 | 2014-02-25 16:11:46 +0000 | [diff] [blame] | 77 | template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14 |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 78 | template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14 |
Eric Fiselier | 5839fed | 2016-07-18 00:35:56 +0000 | [diff] [blame] | 79 | |
| 80 | // [tuple.apply], calling a function with a tuple of arguments: |
| 81 | template <class F, class Tuple> |
| 82 | constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17 |
| 83 | template <class T, class Tuple> |
| 84 | constexpr T make_from_tuple(Tuple&& t); // C++17 |
| 85 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 86 | // 20.4.1.4, tuple helper classes: |
Eric Fiselier | f9a20c2 | 2016-11-13 20:43:50 +0000 | [diff] [blame] | 87 | template <class T> class tuple_size; |
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> |
| 90 | constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17 |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 91 | template <size_t I, class T> class tuple_element; // undefined |
| 92 | template <size_t I, class... T> class tuple_element<I, tuple<T...>>; |
| 93 | template <size_t I, class T> |
| 94 | using tuple_element_t = typename tuple_element <I, T>::type; // C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 95 | |
| 96 | // 20.4.1.5, element access: |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 97 | template <size_t I, class... T> |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 98 | typename tuple_element<I, tuple<T...>>::type& |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 99 | get(tuple<T...>&) noexcept; // constexpr in C++14 |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 100 | template <size_t I, class... T> |
| 101 | const typename tuple_element<I, tuple<T...>>::type& |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 102 | get(const tuple<T...>&) noexcept; // constexpr in C++14 |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 103 | template <size_t I, class... T> |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 104 | typename tuple_element<I, tuple<T...>>::type&& |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 105 | get(tuple<T...>&&) noexcept; // constexpr in C++14 |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 106 | template <size_t I, class... T> |
| 107 | const typename tuple_element<I, tuple<T...>>::type&& |
| 108 | get(const tuple<T...>&&) noexcept; // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 109 | |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 110 | template <class T1, class... T> |
| 111 | constexpr T1& get(tuple<T...>&) noexcept; // C++14 |
| 112 | template <class T1, class... T> |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 113 | constexpr const T1& get(const tuple<T...>&) noexcept; // C++14 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 114 | template <class T1, class... T> |
| 115 | constexpr T1&& get(tuple<T...>&&) noexcept; // C++14 |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 116 | template <class T1, class... T> |
| 117 | constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 118 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 119 | // 20.4.1.6, relational operators: |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 120 | template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
| 121 | template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
| 122 | template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
| 123 | template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
| 124 | template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
| 125 | template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | |
| 127 | template <class... Types, class Alloc> |
| 128 | struct uses_allocator<tuple<Types...>, Alloc>; |
| 129 | |
| 130 | template <class... Types> |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 131 | void |
| 132 | swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 133 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 134 | } // std |
| 135 | |
| 136 | */ |
| 137 | |
| 138 | #include <__config> |
| 139 | #include <__tuple> |
| 140 | #include <cstddef> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 141 | #include <type_traits> |
Howard Hinnant | 6cc99fa | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 142 | #include <__functional_base> |
| 143 | #include <utility> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 145 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 146 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 147 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 148 | |
| 149 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 150 | |
| 151 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 152 | |
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 | { |
| 172 | _Hp value; |
| 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() |
| 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&) |
| 198 | : value() |
| 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) |
| 205 | : value(allocator_arg_t(), __a) |
| 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) |
| 212 | : value(__a) |
| 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)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +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) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +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) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +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) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +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 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +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 | |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +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> |
| 369 | struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> |
| 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> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 474 | class _LIBCPP_TYPE_VIS_ONLY tuple |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 475 | { |
| 476 | typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base; |
| 477 | |
| 478 | base base_; |
| 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 | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 558 | using _Deduced = __deduce_tuple_like<_Tuple>; |
| 559 | using _QualType = typename _Deduced::_QualType; |
| 560 | static_assert(__tuple_like<typename _Deduced::_RawType>::value, ""); |
| 561 | return __tuple_convertible<_QualType, tuple>::value; |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | template <class _Tuple> |
| 565 | static constexpr bool __enable_explicit() { |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 566 | using _Deduced = __deduce_tuple_like<_Tuple>; |
| 567 | using _QualType = typename _Deduced::_QualType; |
| 568 | static_assert(__tuple_like<typename _Deduced::_RawType>::value, ""); |
| 569 | return __tuple_constructible<_QualType, tuple>::value |
| 570 | && !__tuple_convertible<_QualType, tuple>::value; |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 571 | } |
| 572 | }; |
| 573 | |
| 574 | template <class _Dummy> |
| 575 | struct _CheckTupleLikeConstructor<true, true, _Dummy> |
| 576 | { |
| 577 | // This trait is used to disable the tuple-like constructor when |
| 578 | // the UTypes... constructor should be selected instead. |
| 579 | // See LWG issue #2549. |
| 580 | template <class _Tuple> |
| 581 | using _PreferTupleLikeConstructor = __lazy_or< |
| 582 | // Don't attempt the two checks below if the tuple we are given |
| 583 | // has the same type as this tuple. |
| 584 | is_same<typename __uncvref<_Tuple>::type, tuple>, |
| 585 | __lazy_and< |
| 586 | __lazy_not<is_constructible<_Tp..., _Tuple>>, |
| 587 | __lazy_not<is_convertible<_Tuple, _Tp...>> |
| 588 | > |
| 589 | >; |
| 590 | |
| 591 | template <class _Tuple> |
| 592 | static constexpr bool __enable_implicit() { |
| 593 | return __lazy_and< |
| 594 | __tuple_convertible<_Tuple, tuple>, |
| 595 | _PreferTupleLikeConstructor<_Tuple> |
| 596 | >::value; |
| 597 | } |
| 598 | |
| 599 | template <class _Tuple> |
| 600 | static constexpr bool __enable_explicit() { |
| 601 | return __lazy_and< |
| 602 | __tuple_constructible<_Tuple, tuple>, |
| 603 | _PreferTupleLikeConstructor<_Tuple>, |
| 604 | __lazy_not<__tuple_convertible<_Tuple, tuple>> |
| 605 | >::value; |
| 606 | } |
| 607 | }; |
| 608 | |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 609 | template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 610 | typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT; |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 611 | template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 612 | 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] | 613 | template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 614 | typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT; |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 615 | template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 616 | 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] | 617 | public: |
| 618 | |
Eric Fiselier | da1818a | 2015-02-21 02:30:41 +0000 | [diff] [blame] | 619 | template <bool _Dummy = true, class = typename enable_if< |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 620 | _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>() |
Marshall Clow | bbc7c74 | 2014-10-15 10:33:02 +0000 | [diff] [blame] | 621 | >::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 622 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4eebfc3 | 2012-07-06 20:50:27 +0000 | [diff] [blame] | 623 | _LIBCPP_CONSTEXPR tuple() |
| 624 | _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {} |
Howard Hinnant | 5394c1e | 2012-07-06 20:39:45 +0000 | [diff] [blame] | 625 | |
Eric Fiselier | 4be71c6 | 2016-07-25 02:36:42 +0000 | [diff] [blame] | 626 | tuple(tuple const&) = default; |
| 627 | tuple(tuple&&) = default; |
| 628 | |
Eric Fiselier | 55ad3ac | 2016-04-15 03:29:40 +0000 | [diff] [blame] | 629 | template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if< |
| 630 | __lazy_and< |
Eric Fiselier | fa5a105 | 2016-06-21 23:19:13 +0000 | [diff] [blame] | 631 | is_same<allocator_arg_t, _AllocArgT>, |
Eric Fiselier | 55ad3ac | 2016-04-15 03:29:40 +0000 | [diff] [blame] | 632 | __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...> |
| 633 | >::value |
| 634 | >::type> |
| 635 | _LIBCPP_INLINE_VISIBILITY |
| 636 | tuple(_AllocArgT, _Alloc const& __a) |
| 637 | : base_(allocator_arg_t(), __a, |
| 638 | __tuple_indices<>(), __tuple_types<>(), |
| 639 | typename __make_tuple_indices<sizeof...(_Tp), 0>::type(), |
| 640 | __tuple_types<_Tp...>()) {} |
| 641 | |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 642 | template <bool _Dummy = true, |
| 643 | typename enable_if |
| 644 | < |
| 645 | _CheckArgsConstructor< |
| 646 | _Dummy |
Eric Fiselier | fc044a1 | 2016-11-13 19:54:31 +0000 | [diff] [blame] | 647 | >::template __enable_implicit<_Tp const&...>(), |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 648 | bool |
| 649 | >::type = false |
| 650 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 651 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 652 | tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 653 | : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 654 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 655 | typename __make_tuple_indices<0>::type(), |
| 656 | typename __make_tuple_types<tuple, 0>::type(), |
| 657 | __t... |
| 658 | ) {} |
| 659 | |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 660 | template <bool _Dummy = true, |
| 661 | typename enable_if |
| 662 | < |
| 663 | _CheckArgsConstructor< |
| 664 | _Dummy |
Eric Fiselier | fc044a1 | 2016-11-13 19:54:31 +0000 | [diff] [blame] | 665 | >::template __enable_explicit<_Tp const&...>(), |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 666 | bool |
| 667 | >::type = false |
| 668 | > |
| 669 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 670 | explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) |
| 671 | : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 672 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 673 | typename __make_tuple_indices<0>::type(), |
| 674 | typename __make_tuple_types<tuple, 0>::type(), |
| 675 | __t... |
| 676 | ) {} |
| 677 | |
| 678 | template <class _Alloc, bool _Dummy = true, |
| 679 | typename enable_if |
| 680 | < |
| 681 | _CheckArgsConstructor< |
| 682 | _Dummy |
Eric Fiselier | fc044a1 | 2016-11-13 19:54:31 +0000 | [diff] [blame] | 683 | >::template __enable_implicit<_Tp const&...>(), |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 684 | bool |
| 685 | >::type = false |
| 686 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 687 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 688 | tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) |
| 689 | : base_(allocator_arg_t(), __a, |
| 690 | typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 691 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 692 | typename __make_tuple_indices<0>::type(), |
| 693 | typename __make_tuple_types<tuple, 0>::type(), |
| 694 | __t... |
| 695 | ) {} |
| 696 | |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 697 | template <class _Alloc, bool _Dummy = true, |
| 698 | typename enable_if |
| 699 | < |
| 700 | _CheckArgsConstructor< |
| 701 | _Dummy |
Eric Fiselier | fc044a1 | 2016-11-13 19:54:31 +0000 | [diff] [blame] | 702 | >::template __enable_explicit<_Tp const&...>(), |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 703 | bool |
| 704 | >::type = false |
| 705 | > |
| 706 | _LIBCPP_INLINE_VISIBILITY |
| 707 | explicit |
| 708 | tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) |
| 709 | : base_(allocator_arg_t(), __a, |
| 710 | typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 711 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 712 | typename __make_tuple_indices<0>::type(), |
| 713 | typename __make_tuple_types<tuple, 0>::type(), |
| 714 | __t... |
| 715 | ) {} |
| 716 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 717 | template <class ..._Up, |
Eric Fiselier | f2f3637 | 2016-12-08 23:57:08 +0000 | [diff] [blame] | 718 | bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value, |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 719 | typename enable_if |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 720 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 721 | _CheckArgsConstructor< |
Eric Fiselier | f2f3637 | 2016-12-08 23:57:08 +0000 | [diff] [blame] | 722 | sizeof...(_Up) == sizeof...(_Tp) |
| 723 | && !_PackIsTuple |
| 724 | >::template __enable_implicit<_Up...>() || |
| 725 | _CheckArgsConstructor< |
| 726 | _EnableImplicitReducedArityExtension |
| 727 | && sizeof...(_Up) < sizeof...(_Tp) |
| 728 | && !_PackIsTuple |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 729 | >::template __enable_implicit<_Up...>(), |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 730 | bool |
| 731 | >::type = false |
| 732 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 733 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 734 | tuple(_Up&&... __u) |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 735 | _NOEXCEPT_(( |
Marshall Clow | 86d311c | 2014-09-16 17:08:21 +0000 | [diff] [blame] | 736 | is_nothrow_constructible<base, |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 737 | typename __make_tuple_indices<sizeof...(_Up)>::type, |
| 738 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type, |
| 739 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type, |
| 740 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type, |
Marshall Clow | 86d311c | 2014-09-16 17:08:21 +0000 | [diff] [blame] | 741 | _Up... |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 742 | >::value |
| 743 | )) |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 744 | : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 745 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 746 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 747 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 748 | _VSTD::forward<_Up>(__u)...) {} |
| 749 | |
| 750 | template <class ..._Up, |
| 751 | typename enable_if |
| 752 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 753 | _CheckArgsConstructor< |
| 754 | sizeof...(_Up) <= sizeof...(_Tp) |
| 755 | && !_PackExpandsToThisTuple<_Up...>::value |
Eric Fiselier | f2f3637 | 2016-12-08 23:57:08 +0000 | [diff] [blame] | 756 | >::template __enable_explicit<_Up...>() || |
| 757 | _CheckArgsConstructor< |
| 758 | !_EnableImplicitReducedArityExtension |
| 759 | && sizeof...(_Up) < sizeof...(_Tp) |
| 760 | && !_PackExpandsToThisTuple<_Up...>() |
| 761 | >::template __enable_implicit<_Up...>(), |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 762 | bool |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 763 | >::type = false |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 764 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 765 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 766 | explicit |
| 767 | tuple(_Up&&... __u) |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 768 | _NOEXCEPT_(( |
Marshall Clow | 86d311c | 2014-09-16 17:08:21 +0000 | [diff] [blame] | 769 | is_nothrow_constructible<base, |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 770 | typename __make_tuple_indices<sizeof...(_Up)>::type, |
| 771 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type, |
| 772 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type, |
| 773 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type, |
| 774 | _Up... |
| 775 | >::value |
| 776 | )) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 777 | : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 778 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 779 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 780 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 781 | _VSTD::forward<_Up>(__u)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 782 | |
| 783 | template <class _Alloc, class ..._Up, |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 784 | typename enable_if |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 785 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 786 | _CheckArgsConstructor< |
| 787 | sizeof...(_Up) == sizeof...(_Tp) && |
| 788 | !_PackExpandsToThisTuple<_Up...>::value |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 789 | >::template __enable_implicit<_Up...>(), |
| 790 | bool |
| 791 | >::type = false |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 792 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 793 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 794 | tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) |
| 795 | : base_(allocator_arg_t(), __a, |
| 796 | typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 797 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 798 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 799 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 800 | _VSTD::forward<_Up>(__u)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 801 | |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 802 | template <class _Alloc, class ..._Up, |
| 803 | typename enable_if |
| 804 | < |
| 805 | _CheckArgsConstructor< |
| 806 | sizeof...(_Up) == sizeof...(_Tp) && |
| 807 | !_PackExpandsToThisTuple<_Up...>::value |
| 808 | >::template __enable_explicit<_Up...>(), |
| 809 | bool |
| 810 | >::type = false |
| 811 | > |
| 812 | _LIBCPP_INLINE_VISIBILITY |
| 813 | explicit |
| 814 | tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) |
| 815 | : base_(allocator_arg_t(), __a, |
| 816 | typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 817 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 818 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 819 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 820 | _VSTD::forward<_Up>(__u)...) {} |
| 821 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 822 | template <class _Tuple, |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 823 | class _Deduced = __deduce_tuple_like<_Tuple>, |
| 824 | class _TupBase = typename _Deduced::_QualType, |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 825 | typename enable_if |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 826 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 827 | _CheckTupleLikeConstructor< |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 828 | _Deduced::_Size == sizeof...(_Tp) |
| 829 | && !_PackExpandsToThisTuple<_TupBase>::value |
| 830 | >::template __enable_implicit<_TupBase>(), |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 831 | bool |
| 832 | >::type = false |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 833 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 834 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 835 | tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _TupBase>::value)) |
| 836 | : base_(_VSTD::forward<_TupBase>(__t)) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 837 | |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 838 | template <class _Tuple, |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 839 | class _Deduced = __deduce_tuple_like<_Tuple>, |
| 840 | class _TupBase = typename _Deduced::_QualType, |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 841 | typename enable_if |
| 842 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 843 | _CheckTupleLikeConstructor< |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 844 | _Deduced::_Size == sizeof...(_Tp) |
| 845 | && !_PackExpandsToThisTuple<_TupBase>::value |
| 846 | >::template __enable_explicit<_TupBase>(), |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 847 | bool |
| 848 | >::type = false |
| 849 | > |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 850 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 851 | explicit |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 852 | tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _TupBase>::value)) |
| 853 | : base_(_VSTD::forward<_TupBase>(__t)) {} |
Howard Hinnant | dc1345f | 2012-04-01 23:10:42 +0000 | [diff] [blame] | 854 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 855 | template <class _Alloc, class _Tuple, |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 856 | class _Deduced = __deduce_tuple_like<_Tuple>, |
| 857 | class _TupBase = typename _Deduced::_QualType, |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 858 | typename enable_if |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 859 | < |
Eric Fiselier | d501933 | 2016-04-15 18:05:59 +0000 | [diff] [blame] | 860 | _CheckTupleLikeConstructor< |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 861 | _Deduced::_Size == sizeof...(_Tp) |
| 862 | >::template __enable_implicit<_TupBase>(), |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 863 | bool |
| 864 | >::type = false |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 865 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 866 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 867 | tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 868 | : base_(allocator_arg_t(), __a, _VSTD::forward<_TupBase>(__t)) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 869 | |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 870 | template <class _Alloc, class _Tuple, |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 871 | class _Deduced = __deduce_tuple_like<_Tuple>, |
| 872 | class _TupBase = typename _Deduced::_QualType, |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 873 | typename enable_if |
| 874 | < |
| 875 | _CheckTupleLikeConstructor< |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 876 | _Deduced::_Size == sizeof...(_Tp) |
| 877 | >::template __enable_explicit<_TupBase>(), |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 878 | bool |
| 879 | >::type = false |
| 880 | > |
| 881 | _LIBCPP_INLINE_VISIBILITY |
| 882 | explicit |
| 883 | tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 884 | : base_(allocator_arg_t(), __a, _VSTD::forward<_TupBase>(__t)) {} |
Eric Fiselier | 95526d3 | 2016-04-19 01:19:25 +0000 | [diff] [blame] | 885 | |
Eric Fiselier | 4be71c6 | 2016-07-25 02:36:42 +0000 | [diff] [blame] | 886 | using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>; |
| 887 | using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>; |
| 888 | |
| 889 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 890 | tuple& operator=(typename conditional<_CanCopyAssign::value, tuple const&, __nat>::type const& __t) |
Eric Fiselier | 4be71c6 | 2016-07-25 02:36:42 +0000 | [diff] [blame] | 891 | _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value)) |
| 892 | { |
| 893 | base_.operator=(__t.base_); |
| 894 | return *this; |
| 895 | } |
| 896 | |
| 897 | _LIBCPP_INLINE_VISIBILITY |
| 898 | tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t) |
| 899 | _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value)) |
| 900 | { |
| 901 | base_.operator=(static_cast<base&&>(__t.base_)); |
| 902 | return *this; |
| 903 | } |
| 904 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 905 | template <class _Tuple, |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 906 | class _Deduced = __deduce_tuple_like<_Tuple>, |
| 907 | class _TupBase = typename _Deduced::_QualType, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 908 | class = typename enable_if |
| 909 | < |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 910 | __tuple_assignable<_TupBase, tuple>::value |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 911 | >::type |
| 912 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 913 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 914 | tuple& |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 915 | operator=(_Tuple&& __t) |
| 916 | _NOEXCEPT_((is_nothrow_assignable<base&, _TupBase>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 917 | { |
Eric Fiselier | 18e56b4 | 2016-12-14 22:22:38 +0000 | [diff] [blame] | 918 | base_.operator=(_VSTD::forward<_TupBase>(__t)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 919 | return *this; |
| 920 | } |
| 921 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 922 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 923 | void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) |
| 924 | {base_.swap(__t.base_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 925 | }; |
| 926 | |
| 927 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 928 | class _LIBCPP_TYPE_VIS_ONLY tuple<> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 929 | { |
| 930 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 931 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4eebfc3 | 2012-07-06 20:50:27 +0000 | [diff] [blame] | 932 | _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 933 | template <class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 934 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 935 | tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 936 | template <class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 937 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 938 | tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 939 | template <class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 940 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 941 | tuple(array<_Up, 0>) _NOEXCEPT {} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 942 | template <class _Alloc, class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 943 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 944 | tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 945 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 946 | void swap(tuple&) _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 947 | }; |
| 948 | |
| 949 | template <class ..._Tp> |
| 950 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aabf287 | 2011-06-01 19:59:32 +0000 | [diff] [blame] | 951 | typename enable_if |
| 952 | < |
| 953 | __all<__is_swappable<_Tp>::value...>::value, |
| 954 | void |
| 955 | >::type |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 956 | swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) |
| 957 | _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) |
| 958 | {__t.swap(__u);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 959 | |
| 960 | // get |
| 961 | |
| 962 | template <size_t _Ip, class ..._Tp> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 963 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 964 | typename tuple_element<_Ip, tuple<_Tp...> >::type& |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 965 | get(tuple<_Tp...>& __t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 966 | { |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 967 | typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 968 | return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get(); |
| 969 | } |
| 970 | |
| 971 | template <size_t _Ip, class ..._Tp> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 972 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 973 | const typename tuple_element<_Ip, tuple<_Tp...> >::type& |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 974 | get(const tuple<_Tp...>& __t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 975 | { |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 976 | typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 977 | return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get(); |
| 978 | } |
| 979 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 980 | template <size_t _Ip, class ..._Tp> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 981 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 982 | typename tuple_element<_Ip, tuple<_Tp...> >::type&& |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 983 | get(tuple<_Tp...>&& __t) _NOEXCEPT |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 984 | { |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 985 | typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; |
Howard Hinnant | 56a85ca | 2011-01-25 16:31:30 +0000 | [diff] [blame] | 986 | return static_cast<type&&>( |
Douglas Gregor | 6c66994 | 2011-01-25 16:14:21 +0000 | [diff] [blame] | 987 | static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get()); |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 988 | } |
| 989 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 990 | template <size_t _Ip, class ..._Tp> |
| 991 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 992 | const typename tuple_element<_Ip, tuple<_Tp...> >::type&& |
| 993 | get(const tuple<_Tp...>&& __t) _NOEXCEPT |
| 994 | { |
| 995 | typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; |
| 996 | return static_cast<const type&&>( |
| 997 | static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get()); |
| 998 | } |
| 999 | |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1000 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1001 | |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1002 | namespace __find_detail { |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1003 | |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1004 | static constexpr size_t __not_found = -1; |
| 1005 | static constexpr size_t __ambiguous = __not_found - 1; |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1006 | |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1007 | inline _LIBCPP_INLINE_VISIBILITY |
| 1008 | constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) { |
| 1009 | return !__matches ? __res : |
| 1010 | (__res == __not_found ? __curr_i : __ambiguous); |
| 1011 | } |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1012 | |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1013 | template <size_t _Nx> |
| 1014 | inline _LIBCPP_INLINE_VISIBILITY |
| 1015 | constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) { |
| 1016 | return __i == _Nx ? __not_found : |
| 1017 | __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]); |
| 1018 | } |
| 1019 | |
| 1020 | template <class _T1, class ..._Args> |
| 1021 | struct __find_exactly_one_checked { |
| 1022 | static constexpr bool __matches[] = {is_same<_T1, _Args>::value...}; |
| 1023 | static constexpr size_t value = __find_detail::__find_idx(0, __matches); |
| 1024 | static_assert (value != __not_found, "type not found in type list" ); |
| 1025 | static_assert(value != __ambiguous,"type occurs more than once in type list"); |
| 1026 | }; |
| 1027 | |
Eric Fiselier | 990090f | 2016-07-02 03:46:08 +0000 | [diff] [blame] | 1028 | template <class _T1> |
| 1029 | struct __find_exactly_one_checked<_T1> { |
| 1030 | static_assert(!is_same<_T1, _T1>::value, "type not in empty type list"); |
| 1031 | }; |
| 1032 | |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1033 | } // namespace __find_detail; |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1034 | |
| 1035 | template <typename _T1, typename... _Args> |
Eric Fiselier | 22c3e76 | 2016-07-02 03:18:30 +0000 | [diff] [blame] | 1036 | struct __find_exactly_one_t |
| 1037 | : public __find_detail::__find_exactly_one_checked<_T1, _Args...> { |
| 1038 | }; |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1039 | |
| 1040 | template <class _T1, class... _Args> |
| 1041 | inline _LIBCPP_INLINE_VISIBILITY |
| 1042 | constexpr _T1& get(tuple<_Args...>& __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 const& get(tuple<_Args...> const& __tup) noexcept |
| 1050 | { |
| 1051 | return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); |
| 1052 | } |
| 1053 | |
| 1054 | template <class _T1, class... _Args> |
| 1055 | inline _LIBCPP_INLINE_VISIBILITY |
| 1056 | constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept |
| 1057 | { |
Marshall Clow | 01a0e90 | 2013-07-15 20:46:11 +0000 | [diff] [blame] | 1058 | 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] | 1059 | } |
| 1060 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 1061 | template <class _T1, class... _Args> |
| 1062 | inline _LIBCPP_INLINE_VISIBILITY |
| 1063 | constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept |
| 1064 | { |
| 1065 | return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup)); |
| 1066 | } |
| 1067 | |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 1068 | #endif |
| 1069 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1070 | // tie |
| 1071 | |
| 1072 | template <class ..._Tp> |
Marshall Clow | 8e554d9 | 2014-02-25 16:11:46 +0000 | [diff] [blame] | 1073 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1074 | tuple<_Tp&...> |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 1075 | tie(_Tp&... __t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1076 | { |
| 1077 | return tuple<_Tp&...>(__t...); |
| 1078 | } |
| 1079 | |
| 1080 | template <class _Up> |
| 1081 | struct __ignore_t |
| 1082 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1083 | template <class _Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1084 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1085 | const __ignore_t& operator=(_Tp&&) const {return *this;} |
| 1086 | }; |
| 1087 | |
| 1088 | namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); } |
| 1089 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1090 | template <class _Tp> |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 1091 | struct __make_tuple_return_impl |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1092 | { |
| 1093 | typedef _Tp type; |
| 1094 | }; |
| 1095 | |
| 1096 | template <class _Tp> |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 1097 | struct __make_tuple_return_impl<reference_wrapper<_Tp> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1098 | { |
| 1099 | typedef _Tp& type; |
| 1100 | }; |
| 1101 | |
| 1102 | template <class _Tp> |
| 1103 | struct __make_tuple_return |
| 1104 | { |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 1105 | typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1106 | }; |
| 1107 | |
| 1108 | template <class... _Tp> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1109 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1110 | tuple<typename __make_tuple_return<_Tp>::type...> |
| 1111 | make_tuple(_Tp&&... __t) |
| 1112 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1113 | return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 1116 | template <class... _Tp> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1117 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 1118 | tuple<_Tp&&...> |
Howard Hinnant | 74f26f2 | 2012-07-06 21:53:48 +0000 | [diff] [blame] | 1119 | forward_as_tuple(_Tp&&... __t) _NOEXCEPT |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 1120 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1121 | return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...); |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1124 | template <size_t _Ip> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1125 | struct __tuple_equal |
| 1126 | { |
| 1127 | template <class _Tp, class _Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1128 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1129 | bool operator()(const _Tp& __x, const _Up& __y) |
| 1130 | { |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1131 | 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] | 1132 | } |
| 1133 | }; |
| 1134 | |
| 1135 | template <> |
| 1136 | struct __tuple_equal<0> |
| 1137 | { |
| 1138 | template <class _Tp, class _Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1139 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1140 | bool operator()(const _Tp&, const _Up&) |
| 1141 | { |
| 1142 | return true; |
| 1143 | } |
| 1144 | }; |
| 1145 | |
| 1146 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1147 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1148 | bool |
| 1149 | operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1150 | { |
| 1151 | return __tuple_equal<sizeof...(_Tp)>()(__x, __y); |
| 1152 | } |
| 1153 | |
| 1154 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1155 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1156 | bool |
| 1157 | operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1158 | { |
| 1159 | return !(__x == __y); |
| 1160 | } |
| 1161 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1162 | template <size_t _Ip> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1163 | struct __tuple_less |
| 1164 | { |
| 1165 | template <class _Tp, class _Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1166 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1167 | bool operator()(const _Tp& __x, const _Up& __y) |
| 1168 | { |
Duncan P. N. Exon Smith | 07b133f | 2015-01-21 02:51:17 +0000 | [diff] [blame] | 1169 | const size_t __idx = tuple_size<_Tp>::value - _Ip; |
| 1170 | if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y)) |
| 1171 | return true; |
| 1172 | if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x)) |
| 1173 | return false; |
| 1174 | return __tuple_less<_Ip-1>()(__x, __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1175 | } |
| 1176 | }; |
| 1177 | |
| 1178 | template <> |
| 1179 | struct __tuple_less<0> |
| 1180 | { |
| 1181 | template <class _Tp, class _Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1182 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1183 | bool operator()(const _Tp&, const _Up&) |
| 1184 | { |
| 1185 | return false; |
| 1186 | } |
| 1187 | }; |
| 1188 | |
| 1189 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1190 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1191 | bool |
| 1192 | operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1193 | { |
| 1194 | return __tuple_less<sizeof...(_Tp)>()(__x, __y); |
| 1195 | } |
| 1196 | |
| 1197 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1198 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1199 | bool |
| 1200 | operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1201 | { |
| 1202 | return __y < __x; |
| 1203 | } |
| 1204 | |
| 1205 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1206 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1207 | bool |
| 1208 | operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1209 | { |
| 1210 | return !(__x < __y); |
| 1211 | } |
| 1212 | |
| 1213 | template <class ..._Tp, class ..._Up> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1214 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1215 | bool |
| 1216 | operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 1217 | { |
| 1218 | return !(__y < __x); |
| 1219 | } |
| 1220 | |
| 1221 | // tuple_cat |
| 1222 | |
Howard Hinnant | 0e1493e | 2010-12-11 20:47:50 +0000 | [diff] [blame] | 1223 | template <class _Tp, class _Up> struct __tuple_cat_type; |
| 1224 | |
| 1225 | template <class ..._Ttypes, class ..._Utypes> |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 1226 | struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1227 | { |
Howard Hinnant | 0e1493e | 2010-12-11 20:47:50 +0000 | [diff] [blame] | 1228 | typedef tuple<_Ttypes..., _Utypes...> type; |
| 1229 | }; |
| 1230 | |
| 1231 | template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples> |
| 1232 | struct __tuple_cat_return_1 |
| 1233 | { |
| 1234 | }; |
| 1235 | |
| 1236 | template <class ..._Types, class _Tuple0> |
| 1237 | struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0> |
| 1238 | { |
| 1239 | typedef typename __tuple_cat_type<tuple<_Types...>, |
| 1240 | typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type |
| 1241 | type; |
| 1242 | }; |
| 1243 | |
| 1244 | template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples> |
| 1245 | struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...> |
| 1246 | : public __tuple_cat_return_1< |
| 1247 | typename __tuple_cat_type< |
| 1248 | tuple<_Types...>, |
| 1249 | typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type |
| 1250 | >::type, |
| 1251 | __tuple_like<typename remove_reference<_Tuple1>::type>::value, |
| 1252 | _Tuple1, _Tuples...> |
| 1253 | { |
| 1254 | }; |
| 1255 | |
| 1256 | template <class ..._Tuples> struct __tuple_cat_return; |
| 1257 | |
| 1258 | template <class _Tuple0, class ..._Tuples> |
| 1259 | struct __tuple_cat_return<_Tuple0, _Tuples...> |
| 1260 | : public __tuple_cat_return_1<tuple<>, |
| 1261 | __tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0, |
| 1262 | _Tuples...> |
| 1263 | { |
| 1264 | }; |
| 1265 | |
| 1266 | template <> |
| 1267 | struct __tuple_cat_return<> |
| 1268 | { |
| 1269 | typedef tuple<> type; |
| 1270 | }; |
| 1271 | |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1272 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 0e1493e | 2010-12-11 20:47:50 +0000 | [diff] [blame] | 1273 | tuple<> |
| 1274 | tuple_cat() |
| 1275 | { |
| 1276 | return tuple<>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1279 | template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples> |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1280 | struct __tuple_cat_return_ref_imp; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1281 | |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1282 | template <class ..._Types, size_t ..._I0, class _Tuple0> |
| 1283 | struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1284 | { |
Howard Hinnant | 0e1493e | 2010-12-11 20:47:50 +0000 | [diff] [blame] | 1285 | typedef typename remove_reference<_Tuple0>::type _T0; |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1286 | typedef tuple<_Types..., typename __apply_cv<_Tuple0, |
| 1287 | typename tuple_element<_I0, _T0>::type>::type&&...> type; |
| 1288 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1289 | |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1290 | template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples> |
| 1291 | struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, |
| 1292 | _Tuple0, _Tuple1, _Tuples...> |
| 1293 | : public __tuple_cat_return_ref_imp< |
| 1294 | tuple<_Types..., typename __apply_cv<_Tuple0, |
| 1295 | typename tuple_element<_I0, |
| 1296 | typename remove_reference<_Tuple0>::type>::type>::type&&...>, |
| 1297 | typename __make_tuple_indices<tuple_size<typename |
| 1298 | remove_reference<_Tuple1>::type>::value>::type, |
| 1299 | _Tuple1, _Tuples...> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1300 | { |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1301 | }; |
| 1302 | |
| 1303 | template <class _Tuple0, class ..._Tuples> |
| 1304 | struct __tuple_cat_return_ref |
| 1305 | : public __tuple_cat_return_ref_imp<tuple<>, |
| 1306 | typename __make_tuple_indices< |
| 1307 | tuple_size<typename remove_reference<_Tuple0>::type>::value |
| 1308 | >::type, _Tuple0, _Tuples...> |
| 1309 | { |
| 1310 | }; |
| 1311 | |
| 1312 | template <class _Types, class _I0, class _J0> |
| 1313 | struct __tuple_cat; |
| 1314 | |
| 1315 | template <class ..._Types, size_t ..._I0, size_t ..._J0> |
Howard Hinnant | f83417b | 2011-01-24 16:07:25 +0000 | [diff] [blame] | 1316 | struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> > |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1317 | { |
| 1318 | template <class _Tuple0> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1319 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1320 | typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type |
| 1321 | operator()(tuple<_Types...> __t, _Tuple0&& __t0) |
| 1322 | { |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1323 | return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))..., |
| 1324 | _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...); |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | template <class _Tuple0, class _Tuple1, class ..._Tuples> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1328 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1329 | typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type |
| 1330 | operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls) |
| 1331 | { |
| 1332 | typedef typename remove_reference<_Tuple0>::type _T0; |
| 1333 | typedef typename remove_reference<_Tuple1>::type _T1; |
| 1334 | return __tuple_cat< |
| 1335 | tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>, |
| 1336 | typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type, |
| 1337 | typename __make_tuple_indices<tuple_size<_T1>::value>::type>() |
Marshall Clow | 1d927e3 | 2013-10-05 18:46:37 +0000 | [diff] [blame] | 1338 | (forward_as_tuple( |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1339 | _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))..., |
| 1340 | _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))... |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1341 | ), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1342 | _VSTD::forward<_Tuple1>(__t1), |
| 1343 | _VSTD::forward<_Tuples>(__tpls)...); |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1344 | } |
| 1345 | }; |
| 1346 | |
| 1347 | template <class _Tuple0, class... _Tuples> |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 1348 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | e48e366 | 2010-12-12 23:04:37 +0000 | [diff] [blame] | 1349 | typename __tuple_cat_return<_Tuple0, _Tuples...>::type |
| 1350 | tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) |
| 1351 | { |
| 1352 | typedef typename remove_reference<_Tuple0>::type _T0; |
| 1353 | return __tuple_cat<tuple<>, __tuple_indices<>, |
| 1354 | typename __make_tuple_indices<tuple_size<_T0>::value>::type>() |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1355 | (tuple<>(), _VSTD::forward<_Tuple0>(__t0), |
| 1356 | _VSTD::forward<_Tuples>(__tpls)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | template <class ..._Tp, class _Alloc> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1360 | struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1361 | : true_type {}; |
| 1362 | |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 1363 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1364 | |
| 1365 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1366 | template <class _T1, class _T2> |
| 1367 | template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2> |
| 1368 | inline _LIBCPP_INLINE_VISIBILITY |
| 1369 | pair<_T1, _T2>::pair(piecewise_construct_t, |
| 1370 | tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, |
| 1371 | __tuple_indices<_I1...>, __tuple_indices<_I2...>) |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1372 | : first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...), |
| 1373 | second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1374 | { |
| 1375 | } |
Eric Fiselier | e1445fd | 2016-07-25 04:32:07 +0000 | [diff] [blame] | 1376 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1377 | |
Eric Fiselier | 5839fed | 2016-07-18 00:35:56 +0000 | [diff] [blame] | 1378 | #if _LIBCPP_STD_VER > 14 |
| 1379 | template <class _Tp> |
| 1380 | constexpr size_t tuple_size_v = tuple_size<_Tp>::value; |
| 1381 | |
| 1382 | #define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } |
| 1383 | |
| 1384 | template <class _Fn, class _Tuple, size_t ..._Id> |
| 1385 | inline _LIBCPP_INLINE_VISIBILITY |
| 1386 | constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t, |
| 1387 | __tuple_indices<_Id...>) |
| 1388 | _LIBCPP_NOEXCEPT_RETURN( |
| 1389 | _VSTD::__invoke_constexpr( |
| 1390 | _VSTD::forward<_Fn>(__f), |
| 1391 | _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...) |
| 1392 | ) |
| 1393 | |
| 1394 | template <class _Fn, class _Tuple> |
| 1395 | inline _LIBCPP_INLINE_VISIBILITY |
| 1396 | constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t) |
| 1397 | _LIBCPP_NOEXCEPT_RETURN( |
| 1398 | _VSTD::__apply_tuple_impl( |
| 1399 | _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t), |
| 1400 | typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{}) |
| 1401 | ) |
| 1402 | |
| 1403 | template <class _Tp, class _Tuple, size_t... _Idx> |
| 1404 | inline _LIBCPP_INLINE_VISIBILITY |
| 1405 | constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>) |
| 1406 | _LIBCPP_NOEXCEPT_RETURN( |
| 1407 | _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...) |
| 1408 | ) |
| 1409 | |
| 1410 | template <class _Tp, class _Tuple> |
| 1411 | inline _LIBCPP_INLINE_VISIBILITY |
| 1412 | constexpr _Tp make_from_tuple(_Tuple&& __t) |
| 1413 | _LIBCPP_NOEXCEPT_RETURN( |
| 1414 | _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t), |
| 1415 | typename __make_tuple_indices<tuple_size_v<decay_t<_Tuple>>>::type{}) |
| 1416 | ) |
| 1417 | |
| 1418 | #undef _LIBCPP_NOEXCEPT_RETURN |
| 1419 | |
| 1420 | #endif // _LIBCPP_STD_VER > 14 |
| 1421 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1422 | _LIBCPP_END_NAMESPACE_STD |
| 1423 | |
| 1424 | #endif // _LIBCPP_TUPLE |