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(); |
| 24 | explicit tuple(const T&...); |
| 25 | template <class... U> |
| 26 | explicit tuple(U&&...); |
| 27 | tuple(const tuple&) = default; |
| 28 | tuple(tuple&&); |
| 29 | template <class... U> |
| 30 | tuple(const tuple<U...>&); |
| 31 | template <class... U> |
| 32 | tuple(tuple<U...>&&); |
| 33 | template <class U1, class U2> |
| 34 | tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 |
| 35 | template <class U1, class U2> |
| 36 | tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 |
| 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&); |
| 59 | tuple& operator=(tuple&&); |
| 60 | template <class... U> |
| 61 | tuple& operator=(const tuple<U...>&); |
| 62 | template <class... U> |
| 63 | tuple& operator=(tuple<U...>&&); |
| 64 | template <class U1, class U2> |
| 65 | tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 |
| 66 | template <class U1, class U2> |
| 67 | tuple& operator=(pair<U1, U2>&&); //iffsizeof...(T) == 2 |
| 68 | |
| 69 | void swap(tuple&); |
| 70 | }; |
| 71 | |
| 72 | const unspecified ignore; |
| 73 | |
| 74 | template <class... T> tuple<V...> make_tuple(T&&...); |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 75 | template <class... T> tuple<ATypes...> forward_as_tuple(T&&...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 76 | template <class... T> tuple<T&...> tie(T&...); |
| 77 | template <class... T, class... U> tuple<T..., U...> tuple_cat(const tuple<T...>&, const tuple<U...>&); |
| 78 | template <class... T, class... U> tuple<T..., U...> tuple_cat(tuple<T...>&&, const tuple<U...>&); |
| 79 | template <class... T, class... U> tuple<T..., U...> tuple_cat(const tuple<T...>&, tuple<U...>&&); |
| 80 | template <class... T, class... U> tuple<T..., U...> tuple_cat(tuple<T...>&&, tuple<U...>&&); |
| 81 | |
| 82 | // 20.4.1.4, tuple helper classes: |
| 83 | template <class T> class tuple_size; // undefined |
| 84 | template <class... T> class tuple_size<tuple<T...>>; |
| 85 | template <intsize_t I, class T> class tuple_element; // undefined |
| 86 | template <intsize_t I, class... T> class tuple_element<I, tuple<T...>>; |
| 87 | |
| 88 | // 20.4.1.5, element access: |
| 89 | template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type& get(tuple<T...>&); |
| 90 | template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type const& get(const tuple<T...>&); |
| 91 | |
| 92 | // 20.4.1.6, relational operators: |
| 93 | template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); |
| 94 | template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); |
| 95 | template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); |
| 96 | template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); |
| 97 | template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); |
| 98 | template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); |
| 99 | |
| 100 | template <class... Types, class Alloc> |
| 101 | struct uses_allocator<tuple<Types...>, Alloc>; |
| 102 | |
| 103 | template <class... Types> |
| 104 | void swap(tuple<Types...>& x, tuple<Types...>& y); |
| 105 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 | } // std |
| 107 | |
| 108 | */ |
| 109 | |
| 110 | #include <__config> |
| 111 | #include <__tuple> |
| 112 | #include <cstddef> |
| 113 | #include <memory> |
| 114 | #include <type_traits> |
| 115 | |
| 116 | #pragma GCC system_header |
| 117 | |
| 118 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 119 | |
| 120 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 121 | |
| 122 | // tuple_size |
| 123 | |
| 124 | template <class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 125 | class _LIBCPP_VISIBLE tuple_size<tuple<_Tp...>> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | : public integral_constant<size_t, sizeof...(_Tp)> |
| 127 | { |
| 128 | }; |
| 129 | |
| 130 | template <class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 131 | class _LIBCPP_VISIBLE tuple_size<const tuple<_Tp...>> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 132 | : public integral_constant<size_t, sizeof...(_Tp)> |
| 133 | { |
| 134 | }; |
| 135 | |
| 136 | // tuple_element |
| 137 | |
| 138 | template <size_t _Ip, class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 139 | class _LIBCPP_VISIBLE tuple_element<_Ip, tuple<_Tp...>> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 140 | { |
| 141 | public: |
| 142 | typedef typename tuple_element<_Ip, __tuple_types<_Tp...>>::type type; |
| 143 | }; |
| 144 | |
| 145 | template <size_t _Ip, class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 146 | class _LIBCPP_VISIBLE tuple_element<_Ip, const tuple<_Tp...>> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 147 | { |
| 148 | public: |
| 149 | typedef const typename tuple_element<_Ip, __tuple_types<_Tp...>>::type type; |
| 150 | }; |
| 151 | |
| 152 | // __tuple_leaf |
| 153 | |
| 154 | template <size_t _Ip, class _Hp, bool=is_empty<_Hp>::value> |
| 155 | class __tuple_leaf; |
| 156 | |
| 157 | template <size_t _Ip, class _Hp, bool _Ep> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 158 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 159 | void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) |
| 160 | { |
| 161 | swap(__x.get(), __y.get()); |
| 162 | } |
| 163 | |
| 164 | template <size_t _Ip, class _Hp, bool> |
| 165 | class __tuple_leaf |
| 166 | { |
| 167 | _Hp value; |
| 168 | |
| 169 | __tuple_leaf& operator=(const __tuple_leaf&); |
| 170 | public: |
| 171 | _LIBCPP_INLINE_VISIBILITY __tuple_leaf() : value() |
| 172 | {static_assert(!is_reference<_Hp>::value, |
| 173 | "Attempted to default construct a reference element in a tuple");} |
| 174 | |
| 175 | template <class _Alloc> |
| 176 | _LIBCPP_INLINE_VISIBILITY |
| 177 | __tuple_leaf(integral_constant<int, 0>, const _Alloc&) |
| 178 | : value() |
| 179 | {static_assert(!is_reference<_Hp>::value, |
| 180 | "Attempted to default construct a reference element in a tuple");} |
| 181 | |
| 182 | template <class _Alloc> |
| 183 | _LIBCPP_INLINE_VISIBILITY |
| 184 | __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) |
| 185 | : value(allocator_arg_t(), __a) |
| 186 | {static_assert(!is_reference<_Hp>::value, |
| 187 | "Attempted to default construct a reference element in a tuple");} |
| 188 | |
| 189 | template <class _Alloc> |
| 190 | _LIBCPP_INLINE_VISIBILITY |
| 191 | __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) |
| 192 | : value(__a) |
| 193 | {static_assert(!is_reference<_Hp>::value, |
| 194 | "Attempted to default construct a reference element in a tuple");} |
| 195 | |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame^] | 196 | template <class _Tp, |
| 197 | class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 198 | _LIBCPP_INLINE_VISIBILITY |
| 199 | explicit __tuple_leaf(_Tp&& __t) |
| 200 | : value(_STD::forward<_Tp>(__t)) |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame^] | 201 | {static_assert(!is_reference<_Hp>::value || |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 202 | is_lvalue_reference<_Hp>::value && |
| 203 | (is_lvalue_reference<_Tp>::value || |
| 204 | is_same<typename remove_reference<_Tp>::type, |
| 205 | reference_wrapper< |
| 206 | typename remove_reference<_Hp>::type |
| 207 | > |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame^] | 208 | >::value) || |
| 209 | (is_rvalue_reference<_Hp>::value && |
| 210 | !is_lvalue_reference<_Tp>::value), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 211 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 212 | |
| 213 | template <class _Tp, class _Alloc> |
| 214 | _LIBCPP_INLINE_VISIBILITY |
| 215 | explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) |
| 216 | : value(_STD::forward<_Tp>(__t)) |
| 217 | {static_assert(!is_lvalue_reference<_Hp>::value || |
| 218 | is_lvalue_reference<_Hp>::value && |
| 219 | (is_lvalue_reference<_Tp>::value || |
| 220 | is_same<typename remove_reference<_Tp>::type, |
| 221 | reference_wrapper< |
| 222 | typename remove_reference<_Hp>::type |
| 223 | > |
| 224 | >::value), |
| 225 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 226 | |
| 227 | template <class _Tp, class _Alloc> |
| 228 | _LIBCPP_INLINE_VISIBILITY |
| 229 | explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) |
| 230 | : value(allocator_arg_t(), __a, _STD::forward<_Tp>(__t)) |
| 231 | {static_assert(!is_lvalue_reference<_Hp>::value || |
| 232 | is_lvalue_reference<_Hp>::value && |
| 233 | (is_lvalue_reference<_Tp>::value || |
| 234 | is_same<typename remove_reference<_Tp>::type, |
| 235 | reference_wrapper< |
| 236 | typename remove_reference<_Hp>::type |
| 237 | > |
| 238 | >::value), |
| 239 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 240 | |
| 241 | template <class _Tp, class _Alloc> |
| 242 | _LIBCPP_INLINE_VISIBILITY |
| 243 | explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) |
| 244 | : value(_STD::forward<_Tp>(__t), __a) |
| 245 | {static_assert(!is_lvalue_reference<_Hp>::value || |
| 246 | is_lvalue_reference<_Hp>::value && |
| 247 | (is_lvalue_reference<_Tp>::value || |
| 248 | is_same<typename remove_reference<_Tp>::type, |
| 249 | reference_wrapper< |
| 250 | typename remove_reference<_Hp>::type |
| 251 | > |
| 252 | >::value), |
| 253 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 254 | |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame^] | 255 | __tuple_leaf(const __tuple_leaf& __t) |
| 256 | : value(__t.get()) |
| 257 | {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");} |
| 258 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 259 | template <class _Tp> |
| 260 | _LIBCPP_INLINE_VISIBILITY |
| 261 | explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t) |
| 262 | : value(__t.get()) {} |
| 263 | |
| 264 | template <class _Tp> |
| 265 | _LIBCPP_INLINE_VISIBILITY |
| 266 | __tuple_leaf& |
| 267 | operator=(_Tp&& __t) |
| 268 | { |
| 269 | value = _STD::forward<_Tp>(__t); |
| 270 | return *this; |
| 271 | } |
| 272 | |
| 273 | _LIBCPP_INLINE_VISIBILITY |
| 274 | int swap(__tuple_leaf& __t) |
| 275 | { |
| 276 | _STD::swap(*this, __t); |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | _LIBCPP_INLINE_VISIBILITY _Hp& get() {return value;} |
| 281 | _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return value;} |
| 282 | }; |
| 283 | |
| 284 | template <size_t _Ip, class _Hp> |
| 285 | class __tuple_leaf<_Ip, _Hp, true> |
| 286 | : private _Hp |
| 287 | { |
| 288 | |
| 289 | __tuple_leaf& operator=(const __tuple_leaf&); |
| 290 | public: |
| 291 | _LIBCPP_INLINE_VISIBILITY __tuple_leaf() {} |
| 292 | |
| 293 | template <class _Alloc> |
| 294 | _LIBCPP_INLINE_VISIBILITY |
| 295 | __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {} |
| 296 | |
| 297 | template <class _Alloc> |
| 298 | _LIBCPP_INLINE_VISIBILITY |
| 299 | __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) |
| 300 | : _Hp(allocator_arg_t(), __a) {} |
| 301 | |
| 302 | template <class _Alloc> |
| 303 | _LIBCPP_INLINE_VISIBILITY |
| 304 | __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) |
| 305 | : _Hp(__a) {} |
| 306 | |
Howard Hinnant | e049cc5 | 2010-09-27 17:54:17 +0000 | [diff] [blame^] | 307 | template <class _Tp, |
| 308 | class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | _LIBCPP_INLINE_VISIBILITY |
| 310 | explicit __tuple_leaf(_Tp&& __t) |
| 311 | : _Hp(_STD::forward<_Tp>(__t)) {} |
| 312 | |
| 313 | template <class _Tp, class _Alloc> |
| 314 | _LIBCPP_INLINE_VISIBILITY |
| 315 | explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) |
| 316 | : _Hp(_STD::forward<_Tp>(__t)) {} |
| 317 | |
| 318 | template <class _Tp, class _Alloc> |
| 319 | _LIBCPP_INLINE_VISIBILITY |
| 320 | explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) |
| 321 | : _Hp(allocator_arg_t(), __a, _STD::forward<_Tp>(__t)) {} |
| 322 | |
| 323 | template <class _Tp, class _Alloc> |
| 324 | _LIBCPP_INLINE_VISIBILITY |
| 325 | explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) |
| 326 | : _Hp(_STD::forward<_Tp>(__t), __a) {} |
| 327 | |
| 328 | template <class _Tp> |
| 329 | _LIBCPP_INLINE_VISIBILITY |
| 330 | explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t) |
| 331 | : _Hp(__t.get()) {} |
| 332 | |
| 333 | template <class _Tp> |
| 334 | _LIBCPP_INLINE_VISIBILITY |
| 335 | __tuple_leaf& |
| 336 | operator=(_Tp&& __t) |
| 337 | { |
| 338 | _Hp::operator=(_STD::forward<_Tp>(__t)); |
| 339 | return *this; |
| 340 | } |
| 341 | |
| 342 | _LIBCPP_INLINE_VISIBILITY int swap(__tuple_leaf& __t) |
| 343 | { |
| 344 | _STD::swap(*this, __t); |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | _LIBCPP_INLINE_VISIBILITY _Hp& get() {return static_cast<_Hp&>(*this);} |
| 349 | _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return static_cast<const _Hp&>(*this);} |
| 350 | }; |
| 351 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 352 | template <class ..._Tp> |
| 353 | _LIBCPP_INLINE_VISIBILITY |
| 354 | void __swallow(_Tp&&...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 355 | |
| 356 | // __tuple_impl |
| 357 | |
| 358 | template<class _Indx, class ..._Tp> struct __tuple_impl; |
| 359 | |
| 360 | template<size_t ..._Indx, class ..._Tp> |
| 361 | struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> |
| 362 | : public __tuple_leaf<_Indx, _Tp>... |
| 363 | { |
| 364 | template <size_t ..._Uf, class ..._Tf, |
| 365 | size_t ..._Ul, class ..._Tl, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 366 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 367 | explicit |
| 368 | __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>, |
| 369 | __tuple_indices<_Ul...>, __tuple_types<_Tl...>, |
| 370 | _Up&&... __u) : |
| 371 | __tuple_leaf<_Uf, _Tf>(_STD::forward<_Up>(__u))..., |
| 372 | __tuple_leaf<_Ul, _Tl>()... |
| 373 | {} |
| 374 | |
| 375 | template <class _Alloc, size_t ..._Uf, class ..._Tf, |
| 376 | size_t ..._Ul, class ..._Tl, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 377 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 378 | explicit |
| 379 | __tuple_impl(allocator_arg_t, const _Alloc& __a, |
| 380 | __tuple_indices<_Uf...>, __tuple_types<_Tf...>, |
| 381 | __tuple_indices<_Ul...>, __tuple_types<_Tl...>, |
| 382 | _Up&&... __u) : |
| 383 | __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a, |
| 384 | _STD::forward<_Up>(__u))..., |
| 385 | __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)... |
| 386 | {} |
| 387 | |
| 388 | template <class _Tuple, |
| 389 | class = typename enable_if |
| 390 | < |
| 391 | __tuple_convertible<_Tuple, tuple<_Tp...>>::value |
| 392 | >::type |
| 393 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 394 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 395 | __tuple_impl(_Tuple&& __t) |
| 396 | : __tuple_leaf<_Indx, _Tp>(_STD::forward<typename tuple_element<_Indx, |
| 397 | typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))... |
| 398 | {} |
| 399 | |
| 400 | template <class _Alloc, class _Tuple, |
| 401 | class = typename enable_if |
| 402 | < |
| 403 | __tuple_convertible<_Tuple, tuple<_Tp...>>::value |
| 404 | >::type |
| 405 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 406 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) |
| 408 | : __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] | 409 | typename __make_tuple_types<_Tuple>::type>::type>(), __a, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | _STD::forward<typename tuple_element<_Indx, |
| 411 | typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))... |
| 412 | {} |
| 413 | |
| 414 | template <class _Tuple> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 415 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 416 | typename enable_if |
| 417 | < |
| 418 | __tuple_assignable<_Tuple, tuple<_Tp...>>::value, |
| 419 | __tuple_impl& |
| 420 | >::type |
| 421 | operator=(_Tuple&& __t) |
| 422 | { |
| 423 | __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_STD::forward<typename tuple_element<_Indx, |
| 424 | typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...); |
| 425 | return *this; |
| 426 | } |
| 427 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 428 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | void swap(__tuple_impl& __t) |
| 430 | { |
| 431 | __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...); |
| 432 | } |
| 433 | }; |
| 434 | |
| 435 | template <class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 436 | class _LIBCPP_VISIBLE tuple |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 437 | { |
| 438 | typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base; |
| 439 | |
| 440 | base base_; |
| 441 | |
| 442 | template <size_t _Jp, class ..._Up> friend |
| 443 | typename tuple_element<_Jp, tuple<_Up...>>::type& get(tuple<_Up...>&); |
| 444 | template <size_t _Jp, class ..._Up> friend |
| 445 | const typename tuple_element<_Jp, tuple<_Up...>>::type& get(const tuple<_Up...>&); |
| 446 | public: |
| 447 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 449 | explicit tuple(const _Tp& ... __t) |
| 450 | : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 451 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 452 | typename __make_tuple_indices<0>::type(), |
| 453 | typename __make_tuple_types<tuple, 0>::type(), |
| 454 | __t... |
| 455 | ) {} |
| 456 | |
| 457 | template <class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 458 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 459 | tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) |
| 460 | : base_(allocator_arg_t(), __a, |
| 461 | typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 462 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 463 | typename __make_tuple_indices<0>::type(), |
| 464 | typename __make_tuple_types<tuple, 0>::type(), |
| 465 | __t... |
| 466 | ) {} |
| 467 | |
| 468 | template <class ..._Up, |
| 469 | class = typename enable_if |
| 470 | < |
| 471 | sizeof...(_Up) <= sizeof...(_Tp) && |
| 472 | __tuple_convertible |
| 473 | < |
| 474 | tuple<_Up...>, |
| 475 | typename __make_tuple_types<tuple, |
| 476 | sizeof...(_Up) < sizeof...(_Tp) ? |
| 477 | sizeof...(_Up) : |
| 478 | sizeof...(_Tp)>::type |
| 479 | >::value |
| 480 | >::type |
| 481 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 482 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 483 | explicit |
| 484 | tuple(_Up&&... __u) |
| 485 | : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 486 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 487 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 488 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 489 | _STD::forward<_Up>(__u)...) {} |
| 490 | |
| 491 | template <class _Alloc, class ..._Up, |
| 492 | class = typename enable_if |
| 493 | < |
| 494 | sizeof...(_Up) <= sizeof...(_Tp) && |
| 495 | __tuple_convertible |
| 496 | < |
| 497 | tuple<_Up...>, |
| 498 | typename __make_tuple_types<tuple, |
| 499 | sizeof...(_Up) < sizeof...(_Tp) ? |
| 500 | sizeof...(_Up) : |
| 501 | sizeof...(_Tp)>::type |
| 502 | >::value |
| 503 | >::type |
| 504 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 505 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 506 | tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) |
| 507 | : base_(allocator_arg_t(), __a, |
| 508 | typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 509 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 510 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 511 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 512 | _STD::forward<_Up>(__u)...) {} |
| 513 | |
| 514 | template <class _Tuple, |
| 515 | class = typename enable_if |
| 516 | < |
| 517 | __tuple_convertible<_Tuple, tuple>::value |
| 518 | >::type |
| 519 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 520 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 521 | tuple(_Tuple&& __t) |
| 522 | : base_(_STD::forward<_Tuple>(__t)) {} |
| 523 | |
| 524 | template <class _Alloc, class _Tuple, |
| 525 | class = typename enable_if |
| 526 | < |
| 527 | __tuple_convertible<_Tuple, tuple>::value |
| 528 | >::type |
| 529 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 530 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 531 | tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) |
| 532 | : base_(allocator_arg_t(), __a, _STD::forward<_Tuple>(__t)) {} |
| 533 | |
| 534 | template <class _Tuple, |
| 535 | class = typename enable_if |
| 536 | < |
| 537 | __tuple_assignable<_Tuple, tuple>::value |
| 538 | >::type |
| 539 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 540 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 541 | tuple& |
| 542 | operator=(_Tuple&& __t) |
| 543 | { |
| 544 | base_.operator=(_STD::forward<_Tuple>(__t)); |
| 545 | return *this; |
| 546 | } |
| 547 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 548 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 549 | void swap(tuple& __t) {base_.swap(__t.base_);} |
| 550 | }; |
| 551 | |
| 552 | template <> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 553 | class _LIBCPP_VISIBLE tuple<> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 554 | { |
| 555 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 556 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | tuple() {} |
| 558 | template <class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 559 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 560 | tuple(allocator_arg_t, const _Alloc&) {} |
| 561 | template <class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 562 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 563 | tuple(allocator_arg_t, const _Alloc&, const tuple&) {} |
| 564 | template <class _U> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 565 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | tuple(array<_U, 0>) {} |
| 567 | template <class _Alloc, class _U> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 568 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 569 | tuple(allocator_arg_t, const _Alloc&, array<_U, 0>) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 570 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 571 | void swap(tuple&) {} |
| 572 | }; |
| 573 | |
| 574 | template <class ..._Tp> |
| 575 | inline _LIBCPP_INLINE_VISIBILITY |
| 576 | void |
| 577 | swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) {__t.swap(__u);} |
| 578 | |
| 579 | // get |
| 580 | |
| 581 | template <size_t _Ip, class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 582 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 583 | typename tuple_element<_Ip, tuple<_Tp...>>::type& |
| 584 | get(tuple<_Tp...>& __t) |
| 585 | { |
| 586 | typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type; |
| 587 | return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get(); |
| 588 | } |
| 589 | |
| 590 | template <size_t _Ip, class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 591 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 592 | const typename tuple_element<_Ip, tuple<_Tp...>>::type& |
| 593 | get(const tuple<_Tp...>& __t) |
| 594 | { |
| 595 | typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type; |
| 596 | return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get(); |
| 597 | } |
| 598 | |
| 599 | // tie |
| 600 | |
| 601 | template <class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 602 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 603 | tuple<_Tp&...> |
| 604 | tie(_Tp&... __t) |
| 605 | { |
| 606 | return tuple<_Tp&...>(__t...); |
| 607 | } |
| 608 | |
| 609 | template <class _Up> |
| 610 | struct __ignore_t |
| 611 | { |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 612 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 613 | __ignore_t() {} |
| 614 | template <class _Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 615 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 616 | __ignore_t(_Tp&&) {} |
| 617 | template <class _Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 618 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | const __ignore_t& operator=(_Tp&&) const {return *this;} |
| 620 | }; |
| 621 | |
| 622 | namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); } |
| 623 | |
| 624 | template <class _Tp> class reference_wrapper; |
| 625 | |
| 626 | template <class _Tp> |
| 627 | struct ___make_tuple_return |
| 628 | { |
| 629 | typedef _Tp type; |
| 630 | }; |
| 631 | |
| 632 | template <class _Tp> |
| 633 | struct ___make_tuple_return<reference_wrapper<_Tp>> |
| 634 | { |
| 635 | typedef _Tp& type; |
| 636 | }; |
| 637 | |
| 638 | template <class _Tp> |
| 639 | struct __make_tuple_return |
| 640 | { |
| 641 | typedef typename ___make_tuple_return<typename decay<_Tp>::type>::type type; |
| 642 | }; |
| 643 | |
| 644 | template <class... _Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 645 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 646 | tuple<typename __make_tuple_return<_Tp>::type...> |
| 647 | make_tuple(_Tp&&... __t) |
| 648 | { |
| 649 | return tuple<typename __make_tuple_return<_Tp>::type...>(_STD::forward<_Tp>(__t)...); |
| 650 | } |
| 651 | |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 652 | template <class... _Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 653 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 654 | tuple<_Tp&&...> |
| 655 | forward_as_tuple(_Tp&&... __t) |
| 656 | { |
| 657 | return tuple<_Tp&&...>(_STD::forward<_Tp>(__t)...); |
| 658 | } |
| 659 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 660 | template <size_t _I> |
| 661 | struct __tuple_equal |
| 662 | { |
| 663 | template <class _Tp, class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 664 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 665 | bool operator()(const _Tp& __x, const _Up& __y) |
| 666 | { |
| 667 | return __tuple_equal<_I - 1>()(__x, __y) && get<_I-1>(__x) == get<_I-1>(__y); |
| 668 | } |
| 669 | }; |
| 670 | |
| 671 | template <> |
| 672 | struct __tuple_equal<0> |
| 673 | { |
| 674 | template <class _Tp, class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 675 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 676 | bool operator()(const _Tp&, const _Up&) |
| 677 | { |
| 678 | return true; |
| 679 | } |
| 680 | }; |
| 681 | |
| 682 | template <class ..._Tp, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 683 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 684 | bool |
| 685 | operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 686 | { |
| 687 | return __tuple_equal<sizeof...(_Tp)>()(__x, __y); |
| 688 | } |
| 689 | |
| 690 | template <class ..._Tp, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 691 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 692 | bool |
| 693 | operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 694 | { |
| 695 | return !(__x == __y); |
| 696 | } |
| 697 | |
| 698 | template <size_t _I> |
| 699 | struct __tuple_less |
| 700 | { |
| 701 | template <class _Tp, class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 702 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 703 | bool operator()(const _Tp& __x, const _Up& __y) |
| 704 | { |
| 705 | return __tuple_less<_I-1>()(__x, __y) || |
| 706 | (!__tuple_less<_I-1>()(__y, __x) && get<_I-1>(__x) < get<_I-1>(__y)); |
| 707 | } |
| 708 | }; |
| 709 | |
| 710 | template <> |
| 711 | struct __tuple_less<0> |
| 712 | { |
| 713 | template <class _Tp, class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 714 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 715 | bool operator()(const _Tp&, const _Up&) |
| 716 | { |
| 717 | return false; |
| 718 | } |
| 719 | }; |
| 720 | |
| 721 | template <class ..._Tp, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 722 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 723 | bool |
| 724 | operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 725 | { |
| 726 | return __tuple_less<sizeof...(_Tp)>()(__x, __y); |
| 727 | } |
| 728 | |
| 729 | template <class ..._Tp, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 730 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 731 | bool |
| 732 | operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 733 | { |
| 734 | return __y < __x; |
| 735 | } |
| 736 | |
| 737 | template <class ..._Tp, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 738 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 739 | bool |
| 740 | operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 741 | { |
| 742 | return !(__x < __y); |
| 743 | } |
| 744 | |
| 745 | template <class ..._Tp, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 746 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 747 | bool |
| 748 | operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 749 | { |
| 750 | return !(__y < __x); |
| 751 | } |
| 752 | |
| 753 | // tuple_cat |
| 754 | |
| 755 | template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 756 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 757 | tuple<_Tp..., _Up...> |
| 758 | __tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>) |
| 759 | { |
| 760 | return tuple<_Tp..., _Up...>(get<_I1>(__x)..., get<_I2>(__y)...); |
| 761 | } |
| 762 | |
| 763 | template <class... _Tp, class... _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 764 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 765 | tuple<_Tp..., _Up...> |
| 766 | tuple_cat(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 767 | { |
| 768 | return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 769 | __y, typename __make_tuple_indices<sizeof...(_Up)>::type()); |
| 770 | } |
| 771 | |
| 772 | template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 773 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 774 | tuple<_Tp..., _Up...> |
| 775 | __tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>) |
| 776 | { |
| 777 | return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., get<_I2>(__y)...); |
| 778 | } |
| 779 | |
| 780 | template <class... _Tp, class... _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 781 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 782 | tuple<_Tp..., _Up...> |
| 783 | tuple_cat(tuple<_Tp...>&& __x, const tuple<_Up...>& __y) |
| 784 | { |
| 785 | return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 786 | __y, typename __make_tuple_indices<sizeof...(_Up)>::type()); |
| 787 | } |
| 788 | |
| 789 | template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 790 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 791 | tuple<_Tp..., _Up...> |
| 792 | __tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>) |
| 793 | { |
| 794 | return tuple<_Tp..., _Up...>(get<_I1>(__x)..., _STD::forward<_Up>(get<_I2>(__y))...); |
| 795 | } |
| 796 | |
| 797 | template <class... _Tp, class... _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 798 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 799 | tuple<_Tp..., _Up...> |
| 800 | tuple_cat(const tuple<_Tp...>& __x, tuple<_Up...>&& __y) |
| 801 | { |
| 802 | return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 803 | _STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type()); |
| 804 | } |
| 805 | |
| 806 | template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 807 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 808 | tuple<_Tp..., _Up...> |
| 809 | __tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>) |
| 810 | { |
| 811 | return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., _STD::forward<_Up>(get<_I2>(__y))...); |
| 812 | } |
| 813 | |
| 814 | template <class... _Tp, class... _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 815 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 816 | tuple<_Tp..., _Up...> |
| 817 | tuple_cat(tuple<_Tp...>&& __x, tuple<_Up...>&& __y) |
| 818 | { |
| 819 | return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 820 | _STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type()); |
| 821 | } |
| 822 | |
| 823 | template <class ..._Tp, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 824 | struct _LIBCPP_VISIBLE uses_allocator<tuple<_Tp...>, _Alloc> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 825 | : true_type {}; |
| 826 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 827 | template <class _T1, class _T2> |
| 828 | template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2> |
| 829 | inline _LIBCPP_INLINE_VISIBILITY |
| 830 | pair<_T1, _T2>::pair(piecewise_construct_t, |
| 831 | tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, |
| 832 | __tuple_indices<_I1...>, __tuple_indices<_I2...>) |
| 833 | : first(_STD::forward<_Args1>(get<_I1>( __first_args))...), |
| 834 | second(_STD::forward<_Args2>(get<_I2>(__second_args))...) |
| 835 | { |
| 836 | } |
| 837 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 838 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 839 | |
| 840 | _LIBCPP_END_NAMESPACE_STD |
| 841 | |
| 842 | #endif // _LIBCPP_TUPLE |