Changeset f9ce7cd in mainline


Ignore:
Timestamp:
2018-07-05T21:41:21Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6d8a63a
Parents:
9019d85
git-author:
Dzejrou <dzejrou@…> (2018-04-17 20:07:16)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:21)
Message:

cpp: added erase

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/deque.hpp

    r9019d85 rf9ce7cd  
    157157                operator deque_iterator<T, Allocator>()
    158158                {
    159                     return deque_iterator{deq_, idx_};
     159                    return deque_iterator{
     160                        const_cast<deque<T, Allocator>&>(deq_), idx_
     161                    };
    160162                }
    161163
     
    865867            iterator erase(const_iterator position)
    866868            {
    867                 // TODO: implement
     869                auto idx = position.idx();
     870                copy(
     871                    iterator{*this, idx + 1},
     872                    end(),
     873                    iterator{*this, idx}
     874                );
     875
     876                /**
     877                 * Note: We need to not only decrement size,
     878                 *       but also take care of any issues caused
     879                 *       by decrement bucket indices, which pop_back
     880                 *       does for us.
     881                 */
     882                pop_back();
     883
     884                return iterator{*this, idx};
    868885            }
    869886
    870887            iterator erase(const_iterator first, const_iterator last)
    871888            {
    872                 // TODO: implement
     889                if (first == last)
     890                    return first;
     891
     892                auto first_idx = first.idx();
     893                auto last_idx = last.idx();
     894                auto count = distance(first, last);
     895
     896                copy(
     897                    iterator{*this, last_idx},
     898                    end(),
     899                    iterator{*this, first_idx}
     900                );
     901
     902                for (size_type i = 0; i < count; ++i)
     903                    pop_back();
     904
     905                return iterator{*this, first_idx};
    873906            }
    874907
Note: See TracChangeset for help on using the changeset viewer.