Changeset 55cd829 in mainline
- Timestamp:
- 2018-07-05T21:41:20Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bfa86e5
- Parents:
- 78d739d
- git-author:
- Dzejrou <dzejrou@…> (2018-03-30 15:28:07)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:20)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/impl/tuple.hpp
r78d739d r55cd829 288 288 namespace aux 289 289 { 290 template<size_t I >290 template<size_t I, size_t N> 291 291 struct tuple_ops 292 292 { … … 296 296 get<I>(forward<T>(lhs)) = get<I>(forward<U>(rhs)); 297 297 298 tuple_ops<I - 1>::assign(forward<T>(lhs), forward<U>(rhs));298 tuple_ops<I + 1, N>::assign(forward<T>(lhs), forward<U>(rhs)); 299 299 } 300 300 … … 304 304 std::swap(get<I>(lhs), get<I>(rhs)); 305 305 306 tuple_ops<I - 1>::swap(lhs, rhs); 307 } 308 309 // TODO: for rel ops we will need this to be ascending, not descending 310 template<class T, class U> 311 static bool eq(const T& lhs, const T& rhs) 312 { 313 return (get<I>(lhs) == get<I>(rhs)) && tuple_ops<I - 1>::eq(lhs, rhs); 314 } 315 }; 316 317 template<> 318 struct tuple_ops<0> 306 tuple_ops<I + 1, N>::swap(lhs, rhs); 307 } 308 309 template<class T, class U> 310 static bool eq(const T& lhs, const U& rhs) 311 { 312 return (get<I>(lhs) == get<I>(rhs)) && tuple_ops<I + 1, N>::eq(lhs, rhs); 313 } 314 315 template<class T, class U> 316 static bool lt(const T& lhs, const U& rhs) 317 { 318 return (get<I>(lhs) < get<I>(rhs)) || 319 (!(get<I>(rhs) < get<I>(lhs)) && tuple_ops<I + 1, N>::lt(lhs, rhs)); 320 } 321 }; 322 323 template<size_t N> 324 struct tuple_ops<N, N> 319 325 { 320 326 template<class T, class U> 321 327 static void assign(T&& lhs, U&& rhs) 322 328 { 323 get< 0>(forward<T>(lhs)) = get<0>(forward<U>(rhs));329 get<N>(forward<T>(lhs)) = get<N>(forward<U>(rhs)); 324 330 } 325 331 … … 327 333 static void swap(T& lhs, U& rhs) 328 334 { 329 std::swap(get<0>(lhs), get<0>(rhs)); 335 std::swap(get<N>(lhs), get<N>(rhs)); 336 } 337 338 template<class T, class U> 339 static bool eq(const T& lhs, const U& rhs) 340 { 341 return get<N>(lhs) == get<N>(rhs); 342 } 343 344 template<class T, class U> 345 static bool lt(const T& lhs, const U& rhs) 346 { 347 return get<N>(lhs) < get<N>(rhs); 330 348 } 331 349 }; … … 374 392 //{ /* DUMMY BODY */ } 375 393 376 template<class U1, class U2, class = enable_if_t<sizeof...(Ts) == 2, void>> 394 // TODO: pair related construction and assignment needs convertibility, not size 395 template<class U1, class U2> 377 396 constexpr tuple(const pair<U1, U2>& p) 378 397 : base_t{} … … 382 401 } 383 402 384 template<class U1, class U2 , class = enable_if_t<sizeof...(Ts) == 2, void>>403 template<class U1, class U2> 385 404 constexpr tuple(pair<U1, U2>&& p) 386 405 : base_t{} … … 398 417 tuple& operator=(const tuple& other) 399 418 { 400 aux::tuple_ops< sizeof...(Ts) - 1>::assign(*this, other);419 aux::tuple_ops<0, sizeof...(Ts) - 1>::assign(*this, other); 401 420 402 421 return *this; … … 405 424 tuple& operator=(tuple&& other) noexcept(aux::tuple_noexcept_assignment<Ts...>::value) 406 425 { 407 aux::tuple_ops< sizeof...(Ts) - 1>::assign(*this, forward<tuple>(other));426 aux::tuple_ops<0, sizeof...(Ts) - 1>::assign(*this, forward<tuple>(other)); 408 427 409 428 return *this; … … 413 432 tuple& operator=(const tuple<Us...>& other) 414 433 { 415 aux::tuple_ops< sizeof...(Ts) - 1>::assign(*this, other);434 aux::tuple_ops<0, sizeof...(Ts) - 1>::assign(*this, other); 416 435 417 436 return *this; … … 421 440 tuple& operator=(tuple<Us...>&& other) 422 441 { 423 aux::tuple_ops< sizeof...(Ts) - 1>::assign(*this, forward<Us>(other)...);442 aux::tuple_ops<0, sizeof...(Ts) - 1>::assign(*this, forward<Us>(other)...); 424 443 425 444 return *this; 426 445 } 427 446 428 template<class U1, class U2 , class = enable_if_t<sizeof...(Ts) == 2, void>>447 template<class U1, class U2> 429 448 tuple& operator=(const pair<U1, U2>& p) 430 449 { … … 433 452 } 434 453 435 template<class U1, class U2 , class = enable_if_t<sizeof...(Ts) == 2, void>>454 template<class U1, class U2> 436 455 tuple& operator=(pair<U1, U2>&& p) 437 456 { … … 446 465 void swap(tuple& other) noexcept(aux::tuple_noexcept_swap<Ts...>::value) 447 466 { 448 aux::tuple_ops< sizeof...(Ts) - 1>::swap(*this, other);467 aux::tuple_ops<0, sizeof...(Ts) - 1>::swap(*this, other); 449 468 } 450 469 }; … … 455 474 456 475 template<class... Ts, class... Us> 457 constexpr bool operator==(const tuple<Ts...>& lhs, const tuple<Us...> rhs); 476 constexpr bool operator==(const tuple<Ts...>& lhs, const tuple<Us...> rhs) 477 { 478 if constexpr (sizeof...(Ts) == 0) 479 return true; 480 else 481 return aux::tuple_ops<0, sizeof...(Ts) - 1>::eq(lhs, rhs); 482 } 458 483 459 484 template<class... Ts, class... Us> 460 constexpr bool operator<(const tuple<Ts...>& lhs, const tuple<Us...> rhs); 485 constexpr bool operator<(const tuple<Ts...>& lhs, const tuple<Us...> rhs) 486 { 487 if constexpr (sizeof...(Ts) == 0) 488 return false; 489 else 490 return aux::tuple_ops<0, sizeof...(Ts) - 1>::lt(lhs, rhs); 491 } 461 492 462 493 template<class... Ts, class... Us> 463 constexpr bool operator!=(const tuple<Ts...>& lhs, const tuple<Us...> rhs); 494 constexpr bool operator!=(const tuple<Ts...>& lhs, const tuple<Us...> rhs) 495 { 496 return !(lhs == rhs); 497 } 464 498 465 499 template<class... Ts, class... Us> 466 constexpr bool operator>(const tuple<Ts...>& lhs, const tuple<Us...> rhs); 500 constexpr bool operator>(const tuple<Ts...>& lhs, const tuple<Us...> rhs) 501 { 502 return rhs < lhs; 503 } 467 504 468 505 template<class... Ts, class... Us> 469 constexpr bool operator<=(const tuple<Ts...>& lhs, const tuple<Us...> rhs); 506 constexpr bool operator<=(const tuple<Ts...>& lhs, const tuple<Us...> rhs) 507 { 508 return !(rhs < lhs); 509 } 470 510 471 511 template<class... Ts, class... Us> 472 constexpr bool operator>=(const tuple<Ts...>& lhs, const tuple<Us...> rhs); 512 constexpr bool operator>=(const tuple<Ts...>& lhs, const tuple<Us...> rhs) 513 { 514 return !(lhs < rhs); 515 } 473 516 474 517 /**
Note:
See TracChangeset
for help on using the changeset viewer.