📄 _deque.h
字号:
void _M_insert_dispatch(iterator __pos,
_InputIterator __first, _InputIterator __last,
const __false_type&) {
insert(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
}
#else /* _STLP_MEMBER_TEMPLATES */
void insert(iterator __pos,
const value_type* __first, const value_type* __last);
void insert(iterator __pos,
const_iterator __first, const_iterator __last);
#endif /* _STLP_MEMBER_TEMPLATES */
void resize(size_type __new_size, const value_type& __x) {
const size_type __len = size();
if (__new_size < __len)
erase(this->_M_start + __new_size, this->_M_finish);
else
insert(this->_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 - this->_M_start;
if (size_type(__index) < this->size() >> 1) {
copy_backward(this->_M_start, __pos, __next);
pop_front();
}
else {
copy(__next, this->_M_finish, __pos);
pop_back();
}
return this->_M_start + __index;
}
iterator erase(iterator __first, iterator __last);
void clear();
protected: // Internal construction/destruction
void _M_fill_initialize(const value_type& __val);
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void _M_range_initialize(_InputIterator __first,
_InputIterator __last,
const input_iterator_tag &) {
this->_M_initialize_map(0);
_STLP_TRY {
for ( ; __first != __last; ++__first)
push_back(*__first);
}
_STLP_UNWIND(clear());
}
template <class _ForwardIterator>
void _M_range_initialize(_ForwardIterator __first,
_ForwardIterator __last,
const forward_iterator_tag &) {
size_type __n = distance(__first, __last);
this->_M_initialize_map(__n);
_Map_pointer __cur_node;
_STLP_TRY {
for (__cur_node = this->_M_start._M_node;
__cur_node < this->_M_finish._M_node;
++__cur_node) {
_ForwardIterator __mid = __first;
advance(__mid, this->buffer_size());
uninitialized_copy(__first, __mid, *__cur_node);
__first = __mid;
}
uninitialized_copy(__first, __last, this->_M_finish._M_first);
}
_STLP_UNWIND(_Destroy(this->_M_start, iterator(*__cur_node, __cur_node)));
}
#endif /* _STLP_MEMBER_TEMPLATES */
protected: // Internal push_* and pop_*
void _M_push_back_aux_v(const value_type&);
void _M_push_front_aux_v(const value_type&);
# ifndef _STLP_NO_ANACHRONISMS
void _M_push_back_aux();
void _M_push_front_aux();
# endif
void _M_pop_back_aux();
void _M_pop_front_aux();
protected: // Internal insert functions
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void
insert(iterator __pos,
_InputIterator __first,
_InputIterator __last,
const input_iterator_tag &)
{
copy(__first, __last, inserter(*this, __pos));
}
template <class _ForwardIterator>
void insert(iterator __pos,
_ForwardIterator __first,
_ForwardIterator __last,
const forward_iterator_tag &)
{
size_type __n = distance(__first, __last);
if (__pos._M_cur == this->_M_start._M_cur) {
iterator __new_start = _M_reserve_elements_at_front(__n);
_STLP_TRY {
uninitialized_copy(__first, __last, __new_start);
this->_M_start = __new_start;
}
_STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node));
}
else if (__pos._M_cur == this->_M_finish._M_cur) {
iterator __new_finish = _M_reserve_elements_at_back(__n);
_STLP_TRY {
uninitialized_copy(__first, __last, this->_M_finish);
this->_M_finish = __new_finish;
}
_STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1, __new_finish._M_node + 1));
}
else
_M_insert_aux(__pos, __first, __last, __n);
}
#endif /* _STLP_MEMBER_TEMPLATES */
iterator _M_insert_aux(iterator __pos, const value_type& __x);
iterator _M_insert_aux(iterator __pos);
iterator _M_insert_aux_prepare(iterator __pos);
void _M_insert_aux(iterator __pos, size_type __n, const value_type& __x);
#ifdef _STLP_MEMBER_TEMPLATES
template <class _ForwardIterator>
void _M_insert_aux(iterator __pos,
_ForwardIterator __first,
_ForwardIterator __last,
size_type __n) {
const difference_type __elemsbefore = __pos - this->_M_start;
size_type __length = size();
if (__elemsbefore < difference_type(__length / 2)) {
iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = this->_M_start;
__pos = this->_M_start + __elemsbefore;
_STLP_TRY {
if (__elemsbefore >= difference_type(__n)) {
iterator __start_n = this->_M_start + difference_type(__n);
uninitialized_copy(this->_M_start, __start_n, __new_start);
this->_M_start = __new_start;
copy(__start_n, __pos, __old_start);
copy(__first, __last, __pos - difference_type(__n));
}
else {
_ForwardIterator __mid = __first;
advance(__mid, difference_type(__n) - __elemsbefore);
__uninitialized_copy_copy(this->_M_start, __pos, __first, __mid,
__new_start, _IsPODType());
this->_M_start = __new_start;
copy(__mid, __last, __old_start);
}
}
_STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node));
}
else {
iterator __new_finish = _M_reserve_elements_at_back(__n);
iterator __old_finish = this->_M_finish;
const difference_type __elemsafter =
difference_type(__length) - __elemsbefore;
__pos = this->_M_finish - __elemsafter;
_STLP_TRY {
if (__elemsafter > difference_type(__n)) {
iterator __finish_n = this->_M_finish - difference_type(__n);
uninitialized_copy(__finish_n, this->_M_finish, this->_M_finish);
this->_M_finish = __new_finish;
copy_backward(__pos, __finish_n, __old_finish);
copy(__first, __last, __pos);
}
else {
_ForwardIterator __mid = __first;
advance(__mid, __elemsafter);
__uninitialized_copy_copy(__mid, __last, __pos, this->_M_finish, this->_M_finish, _IsPODType());
this->_M_finish = __new_finish;
copy(__first, __mid, __pos);
}
}
_STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1, __new_finish._M_node + 1));
}
}
#else /* _STLP_MEMBER_TEMPLATES */
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);
#endif /* _STLP_MEMBER_TEMPLATES */
iterator _M_reserve_elements_at_front(size_type __n) {
size_type __vacancies = this->_M_start._M_cur - this->_M_start._M_first;
if (__n > __vacancies)
_M_new_elements_at_front(__n - __vacancies);
return this->_M_start - difference_type(__n);
}
iterator _M_reserve_elements_at_back(size_type __n) {
size_type __vacancies = (this->_M_finish._M_last - this->_M_finish._M_cur) - 1;
if (__n > __vacancies)
_M_new_elements_at_back(__n - __vacancies);
return this->_M_finish + difference_type(__n);
}
void _M_new_elements_at_front(size_type __new_elements);
void _M_new_elements_at_back(size_type __new_elements);
protected: // Allocation of _M_map and nodes
// Makes sure the _M_map has space for new nodes. Does not actually
// add the nodes. Can invalidate _M_map pointers. (And consequently,
// deque iterators.)
void _M_reserve_map_at_back (size_type __nodes_to_add = 1) {
if (__nodes_to_add + 1 > this->_M_map_size._M_data - (this->_M_finish._M_node - this->_M_map._M_data))
_M_reallocate_map(__nodes_to_add, false);
}
void _M_reserve_map_at_front (size_type __nodes_to_add = 1) {
if (__nodes_to_add > size_type(this->_M_start._M_node - this->_M_map._M_data))
_M_reallocate_map(__nodes_to_add, true);
}
void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
};
// Nonmember functions.
template <class _Tp, class _Alloc >
inline bool _STLP_CALL operator==(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
{
return __x.size() == __y.size() &&
equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Tp, class _Alloc >
inline bool _STLP_CALL operator<(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
{
return lexicographical_compare(__x.begin(), __x.end(),
__y.begin(), __y.end());
}
#if defined(_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
template <class _Tp, class _Alloc >
inline bool _STLP_CALL operator!=(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
{
return !(__x == __y);
}
template <class _Tp, class _Alloc >
inline bool _STLP_CALL operator>(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
{
return __y < __x;
}
template <class _Tp, class _Alloc >
inline bool _STLP_CALL operator>=(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
{
return !(__x < __y);
}
template <class _Tp, class _Alloc >
inline bool _STLP_CALL operator<=(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
{
return !(__y < __x);
}
# endif /* _STLP_SEPARATE_RELOPS_NAMESPACE */
# if defined(_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
template <class _Tp, class _Alloc>
inline void _STLP_CALL
swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
{
__x.swap(__y);
}
# endif
_STLP_END_NAMESPACE
// do a cleanup
# undef deque
# undef __deque__
# define __deque__ __WORKAROUND_DBG_RENAME(deque)
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_deque.c>
# endif
#if defined (_STLP_DEBUG)
# include <stl/debug/_deque.h>
#endif
# if defined (_STLP_USE_WRAPPER_FOR_ALLOC_PARAM)
# include <stl/wrappers/_deque.h>
# endif
#endif /* _STLP_INTERNAL_DEQUE_H */
// Local Variables:
// mode:C++
// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -