?? stl_deque.h
字號:
_InputIterator __first, _InputIterator __last,
__false_type) {
insert(__pos, __first, __last, __ITERATOR_CATEGORY(__first));
}
#else /* __STL_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 /* __STL_MEMBER_TEMPLATES */
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) {
__stl_debug_check(__check_if_owner(&_M_iter_list, __pos) && (__pos != end()));
iterator __next = __pos;
++__next;
difference_type __index = __pos - _M_start;
if (__index < difference_type(size() >> 1)) {
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);
#ifdef __STL_MEMBER_TEMPLATES
template <class _InputIterator>
void _M_range_initialize(_InputIterator __first,
_InputIterator __last,
input_iterator_tag)
#ifndef __STL_INLINE_MEMBER_TEMPLATES
;
#else
{
_M_initialize_map(0);
__stl_debug_do(_M_iter_list._Safe_init(&_M_start));
__stl_debug_do(_Init_bounds());
__STL_TRY {
for ( ; __first != __last; ++__first)
push_back(*__first);
}
__STL_UNWIND(clear());
}
# endif /* __STL_OUTLINE_MEMBER_TEMPLATES */
template <class _ForwardIterator>
void _M_range_initialize(_ForwardIterator __first,
_ForwardIterator __last,
forward_iterator_tag)
# ifndef __STL_INLINE_MEMBER_TEMPLATES
;
# else
{
size_type __n = 0;
distance(__first, __last, __n);
__stl_debug_do(_M_iter_list._Safe_init(&_M_start));
__stl_debug_do(_Init_bounds());
_M_initialize_map(__n);
_Map_pointer __cur_node;
__STL_TRY {
for (__cur_node = _M_start._M_node;
__cur_node < _M_finish._M_node;
++__cur_node) {
_ForwardIterator __mid = __first;
advance(__mid, __buf_traits::_buf_size);
uninitialized_copy(__first, __mid, *__cur_node);
__first = __mid;
}
uninitialized_copy(__first, __last, _M_finish._M_first);
}
# ifdef __STL_DEBUG
__STL_UNWIND(destroy(_M_start, iterator(&_M_iter_list, *__cur_node, __cur_node)));
# else
__STL_UNWIND(destroy(_M_start, iterator(*__cur_node, __cur_node)));
# endif
}
# endif /* __STL_INLINE_MEMBER_TEMPLATES */
#endif /* __STL_MEMBER_TEMPLATES */
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
#ifdef __STL_MEMBER_TEMPLATES
template <class _InputIterator>
void
insert(iterator __pos,
_InputIterator __first,
_InputIterator __last,
input_iterator_tag)
{
__stl_debug_check(__check_if_owner(&_M_iter_list, __pos) &&
__check_range(__first,__last));
copy(__first, __last, inserter(*this, __pos));
}
template <class _ForwardIterator>
void insert(iterator __pos,
_ForwardIterator __first,
_ForwardIterator __last,
forward_iterator_tag)
# ifndef __STL_INLINE_MEMBER_TEMPLATES
;
# else
{
__stl_debug_check(__check_if_owner(&_M_iter_list, __pos));
size_type __n = 0;
distance(__first, __last, __n);
if (__pos._M_cur == _M_start._M_cur) {
iterator __new_start = _M_reserve_elements_at_front(__n);
__STL_TRY {
uninitialized_copy(__first, __last, __new_start);
_M_start = __new_start;
__stl_debug_do(_M_orphan_start());
}
}
else if (__pos._M_cur == _M_finish._M_cur) {
iterator __new_finish = _M_reserve_elements_at_back(__n);
__STL_TRY {
uninitialized_copy(__first, __last, _M_finish);
_M_finish = __new_finish;
__stl_debug_do(_M_orphan_finish());
}
__STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1, __new_finish._M_node + 1));
}
else
_M_insert_aux(__pos, __first, __last, __n);
}
# endif /* __STL_INLINE_MEMBER_TEMPLATES */
#endif /* __STL_MEMBER_TEMPLATES */
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);
#ifdef __STL_MEMBER_TEMPLATES
template <class _ForwardIterator>
void _M_insert_aux(iterator __pos,
_ForwardIterator __first,
_ForwardIterator __last,
size_type __n)
# ifndef __STL_INLINE_MEMBER_TEMPLATES
;
# else
{
const difference_type __elemsbefore = __pos - _M_start;
size_type __length = size();
if (__elemsbefore < difference_type(__length / 2)) {
iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = _M_start;
__pos = _M_start + __elemsbefore;
__STL_TRY {
if (__elemsbefore >= difference_type(__n)) {
iterator __start_n = _M_start + difference_type(__n);
uninitialized_copy(_M_start, __start_n, __new_start);
_M_start = __new_start;
__stl_debug_do(_M_orphan_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(_M_start, __pos, __first, __mid,
__new_start);
_M_start = __new_start;
__stl_debug_do(_M_orphan_start());
copy(__mid, __last, __old_start);
}
}
__STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
}
else {
iterator __new_finish = _M_reserve_elements_at_back(__n);
iterator __old_finish = _M_finish;
const difference_type __elemsafter =
difference_type(__length) - __elemsbefore;
__pos = _M_finish - __elemsafter;
__STL_TRY {
if (__elemsafter > difference_type(__n)) {
iterator __finish_n = _M_finish - difference_type(__n);
uninitialized_copy(__finish_n, _M_finish, _M_finish);
_M_finish = __new_finish;
__stl_debug_do(_M_orphan_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, _M_finish, _M_finish);
_M_finish = __new_finish;
__stl_debug_do(_M_orphan_finish());
copy(__first, __mid, __pos);
}
}
__STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1, __new_finish._M_node + 1));
}
__stl_debug_do(_Invalidate_all());
}
# endif /* __STL_INLINE_MEMBER_TEMPLATES */
#else /* __STL_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 /* __STL_MEMBER_TEMPLATES */
iterator _M_reserve_elements_at_front(size_type __n) {
size_type __vacancies = _M_start._M_cur - _M_start._M_first;
if (__n > __vacancies)
_M_new_elements_at_front(__n - __vacancies);
__stl_debug_do(_M_start._M_unsafe=true);
return _M_start - difference_type(__n);
}
iterator _M_reserve_elements_at_back(size_type __n) {
size_type __vacancies = (_M_finish._M_last - _M_finish._M_cur) - 1;
if (__n > __vacancies)
_M_new_elements_at_back(__n - __vacancies);
__stl_debug_do(_M_finish._M_unsafe=true);
return _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 > _M_map_size._M_data - (_M_finish._M_node - _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(_M_start._M_node - _M_map._M_data))
_M_reallocate_map(__nodes_to_add, true);
}
void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
#ifdef __STL_NON_TYPE_TMPL_PARAM_BUG
public:
bool operator==(const deque<_Tp,_Alloc,__bufsiz>& __x) const {
return size() == __x.size() && equal(begin(), end(), __x.begin());
}
bool operator!=(const deque<_Tp,_Alloc,__bufsiz>& __x) const {
return size() != __x.size() || !equal(begin(), end(), __x.begin());
}
bool operator<(const deque<_Tp,_Alloc,__bufsiz>& __x) const {
return lexicographical_compare(begin(), end(), __x.begin(), __x.end());
}
bool operator>(const deque<_Tp,_Alloc,__bufsiz>& __x) const {
return __x < *this;
}
bool operator<=(const deque<_Tp,_Alloc,__bufsiz>& __x) const {
return !(__x < *this);
}
bool operator>=(const deque<_Tp,_Alloc,__bufsiz>& __x) const {
return !(*this < __x);
}
# endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
};
// Nonmember functions.
#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
template <class _Tp, class _Alloc, size_t __bufsiz>
inline bool operator==(const deque<_Tp, _Alloc, __bufsiz>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y)
{
return __x.size() == __y.size() &&
equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Tp, class _Alloc, size_t __bufsiz>
inline bool operator<(const deque<_Tp, _Alloc, __bufsiz>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y)
{
return lexicographical_compare(__x.begin(), __x.end(),
__y.begin(), __y.end());
}
#if defined(__STL_USE_SEPARATE_RELOPS_NAMESPACE)
template <class _Tp, class _Alloc, size_t __bufsiz>
inline bool operator>(const deque<_Tp, _Alloc, __bufsiz>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y)
{
return __y < __x;
}
template <class _Tp, class _Alloc, size_t __bufsiz>
inline bool operator>=(const deque<_Tp, _Alloc, __bufsiz>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y)
{
return !(__x < __y);
}
template <class _Tp, class _Alloc, size_t __bufsiz>
inline bool operator<=(const deque<_Tp, _Alloc, __bufsiz>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y)
{
return !(__y < __x);
}
# endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
// do a cleanup
# undef deque
# if defined (__STL_USE_WRAPPER_FOR_ALLOC_PARAM) || \
defined (__STL_NO_DEFAULT_NON_TYPE_PARAM)
// provide a "default" deque adaptor
# if (defined (__STL_DEFAULT_TYPE_PARAM) && defined (__STL_USE_SGI_ALLOCATORS)) || \
! defined (__STL_LIMITED_DEFAULT_TEMPLATES)
template <class _Tp, __STL_DEFAULT_ALLOCATOR_SELECT(_Tp) >
class deque : public __deque__<_Tp,_Alloc,size_t(0)> {
public:
# define _DEQUE_SUPER __deque__<_Tp,_Alloc,size_t(0)>
typedef deque<_Tp, _Alloc> _Self;
# else
template <class _Tp>
class deque : public __deque__<_Tp, __STL_DEFAULT_ALLOCATOR(_Tp), size_t(0)> {
public:
# define _DEQUE_SUPER __deque__<_Tp, __STL_DEFAULT_ALLOCATOR(_Tp), size_t(0)>
typedef deque<_Tp> _Self;
# endif
typedef _DEQUE_SUPER _Super;
__IMPORT_WITH_REVERSE_ITERATORS(_Super)
__IMPORT_SUPER_COPY_ASSIGNMENT(deque, _Self, _DEQUE_SUPER)
deque() : _DEQUE_SUPER() { }
deque(size_type __n, const _Tp& __value) : _DEQUE_SUPER(__n, __value) { }
explicit deque(size_type __n) : _DEQUE_SUPER(__n) { }
deque(const _Tp* __first, const _Tp* __last) : _DEQUE_SUPER(__first, __last) { }
deque(const_iterator __first, const_iterator __last) : _DEQUE_SUPER(__first, __last) { }
~deque() { }
};
# if defined (__STL_BASE_MATCH_BUG)
template <class _Tp>
inline bool
operator==(const deque<_Tp>& __x, const deque<_Tp>& __y) {
return __x.size() == __y.size() && equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Tp>
inline bool
operator<(const deque<_Tp>& __x, const deque<_Tp>& __y) {
return lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
}
# endif /* BASE_MATCH_BUG */
# undef _DEQUE_SUPER
# endif /* __STL_DEFAULT_TYPE_PARAM */
#if defined(__STL_FUNCTION_TMPL_PARTIAL_ORDER) && \
!defined(__STL_NON_TYPE_TMPL_PARAM_BUG)
template <class _Tp, class _Alloc, size_t __bufsiz>
inline void
swap(__deque__<_Tp,_Alloc,__bufsiz>& __x, __deque__<_Tp,_Alloc,__bufsiz>& __y)
{
__x.swap(__y);
}
#endif
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174
#pragma reset woff 1375
#endif
__STL_END_NAMESPACE
# if !defined (__STL_LINK_TIME_INSTANTIATION)
# include <stl_deque.c>
# endif
#endif /* __SGI_STL_INTERNAL_DEQUE_H */
// Local Variables:
// mode:C++
// End:
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -