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 | |
| 196 | template <class _Tp> |
| 197 | _LIBCPP_INLINE_VISIBILITY |
| 198 | explicit __tuple_leaf(_Tp&& __t) |
| 199 | : value(_STD::forward<_Tp>(__t)) |
| 200 | {static_assert(!is_lvalue_reference<_Hp>::value || |
| 201 | is_lvalue_reference<_Hp>::value && |
| 202 | (is_lvalue_reference<_Tp>::value || |
| 203 | is_same<typename remove_reference<_Tp>::type, |
| 204 | reference_wrapper< |
| 205 | typename remove_reference<_Hp>::type |
| 206 | > |
| 207 | >::value), |
| 208 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 209 | |
| 210 | template <class _Tp, class _Alloc> |
| 211 | _LIBCPP_INLINE_VISIBILITY |
| 212 | explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) |
| 213 | : value(_STD::forward<_Tp>(__t)) |
| 214 | {static_assert(!is_lvalue_reference<_Hp>::value || |
| 215 | is_lvalue_reference<_Hp>::value && |
| 216 | (is_lvalue_reference<_Tp>::value || |
| 217 | is_same<typename remove_reference<_Tp>::type, |
| 218 | reference_wrapper< |
| 219 | typename remove_reference<_Hp>::type |
| 220 | > |
| 221 | >::value), |
| 222 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 223 | |
| 224 | template <class _Tp, class _Alloc> |
| 225 | _LIBCPP_INLINE_VISIBILITY |
| 226 | explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) |
| 227 | : value(allocator_arg_t(), __a, _STD::forward<_Tp>(__t)) |
| 228 | {static_assert(!is_lvalue_reference<_Hp>::value || |
| 229 | is_lvalue_reference<_Hp>::value && |
| 230 | (is_lvalue_reference<_Tp>::value || |
| 231 | is_same<typename remove_reference<_Tp>::type, |
| 232 | reference_wrapper< |
| 233 | typename remove_reference<_Hp>::type |
| 234 | > |
| 235 | >::value), |
| 236 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 237 | |
| 238 | template <class _Tp, class _Alloc> |
| 239 | _LIBCPP_INLINE_VISIBILITY |
| 240 | explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) |
| 241 | : value(_STD::forward<_Tp>(__t), __a) |
| 242 | {static_assert(!is_lvalue_reference<_Hp>::value || |
| 243 | is_lvalue_reference<_Hp>::value && |
| 244 | (is_lvalue_reference<_Tp>::value || |
| 245 | is_same<typename remove_reference<_Tp>::type, |
| 246 | reference_wrapper< |
| 247 | typename remove_reference<_Hp>::type |
| 248 | > |
| 249 | >::value), |
| 250 | "Attempted to construct a reference element in a tuple with an rvalue");} |
| 251 | |
| 252 | template <class _Tp> |
| 253 | _LIBCPP_INLINE_VISIBILITY |
| 254 | explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t) |
| 255 | : value(__t.get()) {} |
| 256 | |
| 257 | template <class _Tp> |
| 258 | _LIBCPP_INLINE_VISIBILITY |
| 259 | __tuple_leaf& |
| 260 | operator=(_Tp&& __t) |
| 261 | { |
| 262 | value = _STD::forward<_Tp>(__t); |
| 263 | return *this; |
| 264 | } |
| 265 | |
| 266 | _LIBCPP_INLINE_VISIBILITY |
| 267 | int swap(__tuple_leaf& __t) |
| 268 | { |
| 269 | _STD::swap(*this, __t); |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | _LIBCPP_INLINE_VISIBILITY _Hp& get() {return value;} |
| 274 | _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return value;} |
| 275 | }; |
| 276 | |
| 277 | template <size_t _Ip, class _Hp> |
| 278 | class __tuple_leaf<_Ip, _Hp, true> |
| 279 | : private _Hp |
| 280 | { |
| 281 | |
| 282 | __tuple_leaf& operator=(const __tuple_leaf&); |
| 283 | public: |
| 284 | _LIBCPP_INLINE_VISIBILITY __tuple_leaf() {} |
| 285 | |
| 286 | template <class _Alloc> |
| 287 | _LIBCPP_INLINE_VISIBILITY |
| 288 | __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {} |
| 289 | |
| 290 | template <class _Alloc> |
| 291 | _LIBCPP_INLINE_VISIBILITY |
| 292 | __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) |
| 293 | : _Hp(allocator_arg_t(), __a) {} |
| 294 | |
| 295 | template <class _Alloc> |
| 296 | _LIBCPP_INLINE_VISIBILITY |
| 297 | __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) |
| 298 | : _Hp(__a) {} |
| 299 | |
| 300 | template <class _Tp> |
| 301 | _LIBCPP_INLINE_VISIBILITY |
| 302 | explicit __tuple_leaf(_Tp&& __t) |
| 303 | : _Hp(_STD::forward<_Tp>(__t)) {} |
| 304 | |
| 305 | template <class _Tp, class _Alloc> |
| 306 | _LIBCPP_INLINE_VISIBILITY |
| 307 | explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) |
| 308 | : _Hp(_STD::forward<_Tp>(__t)) {} |
| 309 | |
| 310 | template <class _Tp, class _Alloc> |
| 311 | _LIBCPP_INLINE_VISIBILITY |
| 312 | explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) |
| 313 | : _Hp(allocator_arg_t(), __a, _STD::forward<_Tp>(__t)) {} |
| 314 | |
| 315 | template <class _Tp, class _Alloc> |
| 316 | _LIBCPP_INLINE_VISIBILITY |
| 317 | explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) |
| 318 | : _Hp(_STD::forward<_Tp>(__t), __a) {} |
| 319 | |
| 320 | template <class _Tp> |
| 321 | _LIBCPP_INLINE_VISIBILITY |
| 322 | explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t) |
| 323 | : _Hp(__t.get()) {} |
| 324 | |
| 325 | template <class _Tp> |
| 326 | _LIBCPP_INLINE_VISIBILITY |
| 327 | __tuple_leaf& |
| 328 | operator=(_Tp&& __t) |
| 329 | { |
| 330 | _Hp::operator=(_STD::forward<_Tp>(__t)); |
| 331 | return *this; |
| 332 | } |
| 333 | |
| 334 | _LIBCPP_INLINE_VISIBILITY int swap(__tuple_leaf& __t) |
| 335 | { |
| 336 | _STD::swap(*this, __t); |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | _LIBCPP_INLINE_VISIBILITY _Hp& get() {return static_cast<_Hp&>(*this);} |
| 341 | _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return static_cast<const _Hp&>(*this);} |
| 342 | }; |
| 343 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 344 | template <class ..._Tp> |
| 345 | _LIBCPP_INLINE_VISIBILITY |
| 346 | void __swallow(_Tp&&...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 | |
| 348 | // __tuple_impl |
| 349 | |
| 350 | template<class _Indx, class ..._Tp> struct __tuple_impl; |
| 351 | |
| 352 | template<size_t ..._Indx, class ..._Tp> |
| 353 | struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> |
| 354 | : public __tuple_leaf<_Indx, _Tp>... |
| 355 | { |
| 356 | template <size_t ..._Uf, class ..._Tf, |
| 357 | size_t ..._Ul, class ..._Tl, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 358 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 359 | explicit |
| 360 | __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>, |
| 361 | __tuple_indices<_Ul...>, __tuple_types<_Tl...>, |
| 362 | _Up&&... __u) : |
| 363 | __tuple_leaf<_Uf, _Tf>(_STD::forward<_Up>(__u))..., |
| 364 | __tuple_leaf<_Ul, _Tl>()... |
| 365 | {} |
| 366 | |
| 367 | template <class _Alloc, size_t ..._Uf, class ..._Tf, |
| 368 | size_t ..._Ul, class ..._Tl, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 369 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 370 | explicit |
| 371 | __tuple_impl(allocator_arg_t, const _Alloc& __a, |
| 372 | __tuple_indices<_Uf...>, __tuple_types<_Tf...>, |
| 373 | __tuple_indices<_Ul...>, __tuple_types<_Tl...>, |
| 374 | _Up&&... __u) : |
| 375 | __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a, |
| 376 | _STD::forward<_Up>(__u))..., |
| 377 | __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)... |
| 378 | {} |
| 379 | |
| 380 | template <class _Tuple, |
| 381 | class = typename enable_if |
| 382 | < |
| 383 | __tuple_convertible<_Tuple, tuple<_Tp...>>::value |
| 384 | >::type |
| 385 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 386 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 387 | __tuple_impl(_Tuple&& __t) |
| 388 | : __tuple_leaf<_Indx, _Tp>(_STD::forward<typename tuple_element<_Indx, |
| 389 | typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))... |
| 390 | {} |
| 391 | |
| 392 | template <class _Alloc, class _Tuple, |
| 393 | class = typename enable_if |
| 394 | < |
| 395 | __tuple_convertible<_Tuple, tuple<_Tp...>>::value |
| 396 | >::type |
| 397 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 398 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 399 | __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) |
| 400 | : __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] | 401 | typename __make_tuple_types<_Tuple>::type>::type>(), __a, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 402 | _STD::forward<typename tuple_element<_Indx, |
| 403 | typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))... |
| 404 | {} |
| 405 | |
| 406 | template <class _Tuple> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 407 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 408 | typename enable_if |
| 409 | < |
| 410 | __tuple_assignable<_Tuple, tuple<_Tp...>>::value, |
| 411 | __tuple_impl& |
| 412 | >::type |
| 413 | operator=(_Tuple&& __t) |
| 414 | { |
| 415 | __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_STD::forward<typename tuple_element<_Indx, |
| 416 | typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...); |
| 417 | return *this; |
| 418 | } |
| 419 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 420 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | void swap(__tuple_impl& __t) |
| 422 | { |
| 423 | __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...); |
| 424 | } |
| 425 | }; |
| 426 | |
| 427 | template <class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 428 | class _LIBCPP_VISIBLE tuple |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | { |
| 430 | typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base; |
| 431 | |
| 432 | base base_; |
| 433 | |
| 434 | template <size_t _Jp, class ..._Up> friend |
| 435 | typename tuple_element<_Jp, tuple<_Up...>>::type& get(tuple<_Up...>&); |
| 436 | template <size_t _Jp, class ..._Up> friend |
| 437 | const typename tuple_element<_Jp, tuple<_Up...>>::type& get(const tuple<_Up...>&); |
| 438 | public: |
| 439 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 440 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 441 | explicit tuple(const _Tp& ... __t) |
| 442 | : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 443 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 444 | typename __make_tuple_indices<0>::type(), |
| 445 | typename __make_tuple_types<tuple, 0>::type(), |
| 446 | __t... |
| 447 | ) {} |
| 448 | |
| 449 | template <class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 450 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 451 | tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) |
| 452 | : base_(allocator_arg_t(), __a, |
| 453 | typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 454 | typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), |
| 455 | typename __make_tuple_indices<0>::type(), |
| 456 | typename __make_tuple_types<tuple, 0>::type(), |
| 457 | __t... |
| 458 | ) {} |
| 459 | |
| 460 | template <class ..._Up, |
| 461 | class = typename enable_if |
| 462 | < |
| 463 | sizeof...(_Up) <= sizeof...(_Tp) && |
| 464 | __tuple_convertible |
| 465 | < |
| 466 | tuple<_Up...>, |
| 467 | typename __make_tuple_types<tuple, |
| 468 | sizeof...(_Up) < sizeof...(_Tp) ? |
| 469 | sizeof...(_Up) : |
| 470 | sizeof...(_Tp)>::type |
| 471 | >::value |
| 472 | >::type |
| 473 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 474 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 475 | explicit |
| 476 | tuple(_Up&&... __u) |
| 477 | : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 478 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 479 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 480 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 481 | _STD::forward<_Up>(__u)...) {} |
| 482 | |
| 483 | template <class _Alloc, class ..._Up, |
| 484 | class = typename enable_if |
| 485 | < |
| 486 | sizeof...(_Up) <= sizeof...(_Tp) && |
| 487 | __tuple_convertible |
| 488 | < |
| 489 | tuple<_Up...>, |
| 490 | typename __make_tuple_types<tuple, |
| 491 | sizeof...(_Up) < sizeof...(_Tp) ? |
| 492 | sizeof...(_Up) : |
| 493 | sizeof...(_Tp)>::type |
| 494 | >::value |
| 495 | >::type |
| 496 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 497 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 498 | tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) |
| 499 | : base_(allocator_arg_t(), __a, |
| 500 | typename __make_tuple_indices<sizeof...(_Up)>::type(), |
| 501 | typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), |
| 502 | typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 503 | typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), |
| 504 | _STD::forward<_Up>(__u)...) {} |
| 505 | |
| 506 | template <class _Tuple, |
| 507 | class = typename enable_if |
| 508 | < |
| 509 | __tuple_convertible<_Tuple, tuple>::value |
| 510 | >::type |
| 511 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 512 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 513 | tuple(_Tuple&& __t) |
| 514 | : base_(_STD::forward<_Tuple>(__t)) {} |
| 515 | |
| 516 | template <class _Alloc, class _Tuple, |
| 517 | class = typename enable_if |
| 518 | < |
| 519 | __tuple_convertible<_Tuple, tuple>::value |
| 520 | >::type |
| 521 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 522 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 523 | tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) |
| 524 | : base_(allocator_arg_t(), __a, _STD::forward<_Tuple>(__t)) {} |
| 525 | |
| 526 | template <class _Tuple, |
| 527 | class = typename enable_if |
| 528 | < |
| 529 | __tuple_assignable<_Tuple, tuple>::value |
| 530 | >::type |
| 531 | > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 532 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | tuple& |
| 534 | operator=(_Tuple&& __t) |
| 535 | { |
| 536 | base_.operator=(_STD::forward<_Tuple>(__t)); |
| 537 | return *this; |
| 538 | } |
| 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 | void swap(tuple& __t) {base_.swap(__t.base_);} |
| 542 | }; |
| 543 | |
| 544 | template <> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 545 | class _LIBCPP_VISIBLE tuple<> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 546 | { |
| 547 | public: |
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 | tuple() {} |
| 550 | template <class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 551 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 552 | tuple(allocator_arg_t, const _Alloc&) {} |
| 553 | template <class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 554 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 555 | tuple(allocator_arg_t, const _Alloc&, const tuple&) {} |
| 556 | template <class _U> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 557 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 558 | tuple(array<_U, 0>) {} |
| 559 | template <class _Alloc, class _U> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 560 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 561 | tuple(allocator_arg_t, const _Alloc&, array<_U, 0>) {} |
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 | void swap(tuple&) {} |
| 564 | }; |
| 565 | |
| 566 | template <class ..._Tp> |
| 567 | inline _LIBCPP_INLINE_VISIBILITY |
| 568 | void |
| 569 | swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) {__t.swap(__u);} |
| 570 | |
| 571 | // get |
| 572 | |
| 573 | template <size_t _Ip, class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 574 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | typename tuple_element<_Ip, tuple<_Tp...>>::type& |
| 576 | get(tuple<_Tp...>& __t) |
| 577 | { |
| 578 | typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type; |
| 579 | return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get(); |
| 580 | } |
| 581 | |
| 582 | template <size_t _Ip, class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 583 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 584 | const typename tuple_element<_Ip, tuple<_Tp...>>::type& |
| 585 | get(const tuple<_Tp...>& __t) |
| 586 | { |
| 587 | typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type; |
| 588 | return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get(); |
| 589 | } |
| 590 | |
| 591 | // tie |
| 592 | |
| 593 | template <class ..._Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 594 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 595 | tuple<_Tp&...> |
| 596 | tie(_Tp&... __t) |
| 597 | { |
| 598 | return tuple<_Tp&...>(__t...); |
| 599 | } |
| 600 | |
| 601 | template <class _Up> |
| 602 | struct __ignore_t |
| 603 | { |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 604 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 605 | __ignore_t() {} |
| 606 | template <class _Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 607 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 608 | __ignore_t(_Tp&&) {} |
| 609 | template <class _Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 610 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 611 | const __ignore_t& operator=(_Tp&&) const {return *this;} |
| 612 | }; |
| 613 | |
| 614 | namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); } |
| 615 | |
| 616 | template <class _Tp> class reference_wrapper; |
| 617 | |
| 618 | template <class _Tp> |
| 619 | struct ___make_tuple_return |
| 620 | { |
| 621 | typedef _Tp type; |
| 622 | }; |
| 623 | |
| 624 | template <class _Tp> |
| 625 | struct ___make_tuple_return<reference_wrapper<_Tp>> |
| 626 | { |
| 627 | typedef _Tp& type; |
| 628 | }; |
| 629 | |
| 630 | template <class _Tp> |
| 631 | struct __make_tuple_return |
| 632 | { |
| 633 | typedef typename ___make_tuple_return<typename decay<_Tp>::type>::type type; |
| 634 | }; |
| 635 | |
| 636 | template <class... _Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 637 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 638 | tuple<typename __make_tuple_return<_Tp>::type...> |
| 639 | make_tuple(_Tp&&... __t) |
| 640 | { |
| 641 | return tuple<typename __make_tuple_return<_Tp>::type...>(_STD::forward<_Tp>(__t)...); |
| 642 | } |
| 643 | |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 644 | template <class... _Tp> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 645 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3c1ffba | 2010-08-19 18:59:38 +0000 | [diff] [blame] | 646 | tuple<_Tp&&...> |
| 647 | forward_as_tuple(_Tp&&... __t) |
| 648 | { |
| 649 | return tuple<_Tp&&...>(_STD::forward<_Tp>(__t)...); |
| 650 | } |
| 651 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 652 | template <size_t _I> |
| 653 | struct __tuple_equal |
| 654 | { |
| 655 | template <class _Tp, class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 656 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 657 | bool operator()(const _Tp& __x, const _Up& __y) |
| 658 | { |
| 659 | return __tuple_equal<_I - 1>()(__x, __y) && get<_I-1>(__x) == get<_I-1>(__y); |
| 660 | } |
| 661 | }; |
| 662 | |
| 663 | template <> |
| 664 | struct __tuple_equal<0> |
| 665 | { |
| 666 | template <class _Tp, class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 667 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 668 | bool operator()(const _Tp&, const _Up&) |
| 669 | { |
| 670 | return true; |
| 671 | } |
| 672 | }; |
| 673 | |
| 674 | template <class ..._Tp, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 675 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 676 | bool |
| 677 | operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 678 | { |
| 679 | return __tuple_equal<sizeof...(_Tp)>()(__x, __y); |
| 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 !(__x == __y); |
| 688 | } |
| 689 | |
| 690 | template <size_t _I> |
| 691 | struct __tuple_less |
| 692 | { |
| 693 | template <class _Tp, class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 694 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 695 | bool operator()(const _Tp& __x, const _Up& __y) |
| 696 | { |
| 697 | return __tuple_less<_I-1>()(__x, __y) || |
| 698 | (!__tuple_less<_I-1>()(__y, __x) && get<_I-1>(__x) < get<_I-1>(__y)); |
| 699 | } |
| 700 | }; |
| 701 | |
| 702 | template <> |
| 703 | struct __tuple_less<0> |
| 704 | { |
| 705 | template <class _Tp, class _Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 706 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 707 | bool operator()(const _Tp&, const _Up&) |
| 708 | { |
| 709 | return false; |
| 710 | } |
| 711 | }; |
| 712 | |
| 713 | template <class ..._Tp, class ..._Up> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 714 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 715 | bool |
| 716 | operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) |
| 717 | { |
| 718 | return __tuple_less<sizeof...(_Tp)>()(__x, __y); |
| 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 __y < __x; |
| 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 !(__x < __y); |
| 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 !(__y < __x); |
| 743 | } |
| 744 | |
| 745 | // tuple_cat |
| 746 | |
| 747 | template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 748 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 749 | tuple<_Tp..., _Up...> |
| 750 | __tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>) |
| 751 | { |
| 752 | return tuple<_Tp..., _Up...>(get<_I1>(__x)..., get<_I2>(__y)...); |
| 753 | } |
| 754 | |
| 755 | template <class... _Tp, class... _Up> |
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, const tuple<_Up...>& __y) |
| 759 | { |
| 760 | return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 761 | __y, typename __make_tuple_indices<sizeof...(_Up)>::type()); |
| 762 | } |
| 763 | |
| 764 | template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 765 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 766 | tuple<_Tp..., _Up...> |
| 767 | __tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>) |
| 768 | { |
| 769 | return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., get<_I2>(__y)...); |
| 770 | } |
| 771 | |
| 772 | template <class... _Tp, class... _Up> |
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, const tuple<_Up...>& __y) |
| 776 | { |
| 777 | return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 778 | __y, typename __make_tuple_indices<sizeof...(_Up)>::type()); |
| 779 | } |
| 780 | |
| 781 | template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 782 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 783 | tuple<_Tp..., _Up...> |
| 784 | __tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>) |
| 785 | { |
| 786 | return tuple<_Tp..., _Up...>(get<_I1>(__x)..., _STD::forward<_Up>(get<_I2>(__y))...); |
| 787 | } |
| 788 | |
| 789 | template <class... _Tp, class... _Up> |
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<_Up...>&& __y) |
| 793 | { |
| 794 | return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 795 | _STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type()); |
| 796 | } |
| 797 | |
| 798 | template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 799 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 800 | tuple<_Tp..., _Up...> |
| 801 | __tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>) |
| 802 | { |
| 803 | return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., _STD::forward<_Up>(get<_I2>(__y))...); |
| 804 | } |
| 805 | |
| 806 | template <class... _Tp, class... _Up> |
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<_Up...>&& __y) |
| 810 | { |
| 811 | return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(), |
| 812 | _STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type()); |
| 813 | } |
| 814 | |
| 815 | template <class ..._Tp, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame^] | 816 | struct _LIBCPP_VISIBLE uses_allocator<tuple<_Tp...>, _Alloc> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 817 | : true_type {}; |
| 818 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 819 | template <class _T1, class _T2> |
| 820 | template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2> |
| 821 | inline _LIBCPP_INLINE_VISIBILITY |
| 822 | pair<_T1, _T2>::pair(piecewise_construct_t, |
| 823 | tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, |
| 824 | __tuple_indices<_I1...>, __tuple_indices<_I2...>) |
| 825 | : first(_STD::forward<_Args1>(get<_I1>( __first_args))...), |
| 826 | second(_STD::forward<_Args2>(get<_I2>(__second_args))...) |
| 827 | { |
| 828 | } |
| 829 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 830 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | |
| 832 | _LIBCPP_END_NAMESPACE_STD |
| 833 | |
| 834 | #endif // _LIBCPP_TUPLE |