Changeset f62f1ee in mainline
- Timestamp:
- 2018-07-05T21:41:21Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e5cf551
- Parents:
- 8733ce2a
- git-author:
- Dzejrou <dzejrou@…> (2018-04-20 15:33:39)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:21)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/impl/list.hpp
r8733ce2a rf62f1ee 52 52 list_node(Args&&... args) 53 53 : value{forward<Args>(args)...}, 54 next{ this}, prev{this}54 next{}, prev{} 55 55 { 56 56 next = this; … … 59 59 60 60 list_node(const T& val) 61 : value{val}, next{ this}, prev{this}61 : value{val}, next{}, prev{} 62 62 { 63 63 next = this; … … 232 232 operator list_const_iterator<T>() const 233 233 { 234 return list_const_iterator {current_};234 return list_const_iterator<T>{current_}; 235 235 } 236 236 237 237 private: 238 list_node< T>* current_;238 list_node<value_type>* current_; 239 239 list_node<value_type>* head_; 240 240 }; … … 611 611 iterator emplace(const_iterator position, Args&&... args) 612 612 { 613 // TODO: implement 614 } 615 616 /* private: */ 613 auto node = position.node(); 614 node->prepend(new aux::list_node<value_type>{forward<Args>(args)...}); 615 ++size_; 616 617 if (node == head_) 618 head_ = head_->prev; 619 620 return iterator{node->prev}; 621 } 622 623 iterator insert(const_iterator position, const value_type& val) 624 { 625 return emplace(position, val); 626 } 627 628 iterator insert(const_iterator position, value_type&& val) 629 { 630 return emplace(position, forward<value_type>(val)); 631 } 632 633 iterator insert(const_iterator position, size_type n, const value_type& val) 634 { 635 return insert( 636 position, 637 aux::insert_iterator<value_type>{0u, val}, 638 aux::insert_iterator<value_type>{n} 639 ); 640 } 641 642 template<class InputIterator> 643 iterator insert(const_iterator position, InputIterator first, InputIterator last) 644 { 645 auto node = position.node()->prev; 646 647 while (first != last) 648 { 649 node->append(new aux::list_node<value_type>{*first++}); 650 node = node->next; 651 ++size_; 652 } 653 654 return iterator{position.node()->next}; 655 } 656 657 iterator insert(const_iterator position, initializer_list<value_type> init) 658 { 659 return insert(position, init.begin(), init.end()); 660 } 661 662 iterator erase(const_iterator position) 663 { 664 auto node = position.node(); 665 --size_; 666 667 if (node != get_last_()) 668 { 669 auto next = node->next; 670 auto prev = node->prev; 671 672 next->prev = prev; 673 prev->next = next; 674 675 delete node; 676 677 return iterator{next}; 678 } 679 else 680 { 681 auto prev = node->prev; 682 head_->prev = prev; 683 prev->next = head_; 684 685 delete node; 686 687 return end(); 688 } 689 } 690 691 iterator erase(const_iterator first, const_iterator last) 692 { 693 if (first == last) 694 return end(); 695 696 auto first_node = first.node(); 697 auto last_node = last.node(); 698 auto prev = first_node->prev; 699 auto next = last_node->next; 700 701 prev->append(next); 702 703 while (first_node != next) 704 { 705 auto tmp = first_node; 706 first_node = first_node->next; 707 --size_; 708 709 delete tmp; 710 } 711 712 return iterator{next}; 713 } 714 715 void swap(list& other) 716 noexcept(allocator_traits<allocator_type>::is_always_equal::value) 717 { 718 std::swap(allocator_, other.allocator_); 719 std::swap(head_, other.head_); 720 std::swap(size_, other.size_); 721 } 722 723 void clear() 724 { 725 fini_(); 726 } 727 728 private: 617 729 allocator_type allocator_; 618 730 aux::list_node<value_type>* head_;
Note:
See TracChangeset
for help on using the changeset viewer.