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