设为首页 加入收藏

TOP

C++ STL 源码学习(之deque篇)(六)
2015-07-20 17:30:15 来源: 作者: 【 】 浏览:26
Tags:STL 源码 学习 deque篇
irst) { construct(_M_start._M_cur - 1); --_M_start._M_cur; } else _M_push_front_aux(); } void pop_back() { if (_M_finish._M_cur != _M_finish._M_first) { ///最后一个元素不是最后一个区段的第一个元素 --_M_finish._M_cur; destroy(_M_finish._M_cur); } else _M_pop_back_aux(); } void pop_front() { if (_M_start._M_cur != _M_start._M_last - 1) { destroy(_M_start._M_cur); ++_M_start._M_cur; } else _M_pop_front_aux(); } public: /// Insert ///都是通过函数调用实现的,很清晰 iterator insert(iterator position, const value_type& __x) { if (position._M_cur == _M_start._M_cur) { push_front(__x); return _M_start; } else if (position._M_cur == _M_finish._M_cur) { push_back(__x); iterator __tmp = _M_finish; --__tmp; return __tmp; } else { return _M_insert_aux(position, __x); } } iterator insert(iterator __position) { return insert(__position, value_type()); } void insert(iterator __pos, size_type __n, const value_type& __x) { _M_fill_insert(__pos, __n, __x); } void _M_fill_insert(iterator __pos, size_type __n, const value_type& __x); /// Check whether it's an integral type. If so, it's not an iterator. template void insert(iterator __pos, _InputIterator __first, _InputIterator __last) { typedef typename _Is_integer<_InputIterator>::_Integral _Integral; _M_insert_dispatch(__pos, __first, __last, _Integral()); } template void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x, __true_type) { _M_fill_insert(__pos, (size_type) __n, (value_type) __x); } template void _M_insert_dispatch(iterator __pos, _InputIterator __first, _InputIterator __last, __false_type) { insert(__pos, __first, __last, __ITERATOR_CATEGORY(__first)); } void resize(size_type __new_size, const value_type& __x) { const size_type __len = size(); if (__new_size < __len) erase(_M_start + __new_size, _M_finish); else insert(_M_finish, __new_size - __len, __x); } void resize(size_type new_size) { resize(new_size, value_type()); } public: /// Erase iterator erase(iterator __pos) { iterator __next = __pos; ++__next; difference_type __index = __pos - _M_start; if (size_type(__index) < (this->size() >> 1)) ///位于deque前半段 { copy_backward(_M_start, __pos, __next); pop_front(); } else { copy(__next, _M_finish, __pos); pop_back(); } return _M_start + __index; } iterator erase(iterator __first, iterator __last); void clear(); protected: /// Internal construction/destruction void _M_fill_initialize(const value_type& __value); template void _M_range_initialize(_InputIterator __first, _InputIterator __last, input_iterator_tag); template void _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last, forward_iterator_tag); protected: /// Internal push_* and pop_* void _M_push_back_aux(const value_type&); void _M_push_back_aux(); void _M_push_front_aux(const value_type&); void _M_push_front_aux(); void _M_pop_back_aux(); void _M_pop_front_aux(); protected: /// Internal insert functions template void insert(iterator __pos, _InputIterator __first, _InputIterator __last, input_iterator_tag); template void insert(iterator __pos, _ForwardIterator __first, _ForwardIterator __last, forward_iterator_tag); iterator _M_insert_aux(iterator __pos, const value_type& __x); iterator _M_insert_aux(iterator __pos); void _M_insert_aux(iterator __pos, size_type __n, const value_type& __x); template void _M_insert_aux(iterator __pos, _ForwardIterator __first, _ForwardIterator __last, size_type __n); void _M_insert_aux(iterator __pos, const value_type* __first, const value_type* __last, size_type __n); void _M_insert_aux(iterator __pos, const_iterator __first, const_iterator __last, size_type __n); iterator _M_reserve_elements_at_front(size_type __n) { size_type __vacancies = _M_start._M_cur - _M_start._M_firs
首页 上一页 3 4 5 6 7 8 9 下一页 尾页 6/10/10
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇二叉树的非递归遍历--京东2015笔.. 下一篇HDU 5059 Help him(细节)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)
·Redis - The Real-ti (2025-12-26 08:20:50)
·Bash 脚本教程——Li (2025-12-26 07:53:35)
·实战篇!Linux shell (2025-12-26 07:53:32)