📄 stl_slist.h
字号:
void _M_insert_after_range(_Node_base* __pos, _InIter __first, _InIter __last, __false_type) { while (__first != __last) { __pos = __slist_make_link(__pos, _M_create_node(*__first)); ++__first; } }#else /* __STL_MEMBER_TEMPLATES */ void _M_insert_after_range(_Node_base* __pos, const_iterator __first, const_iterator __last) { while (__first != __last) { __pos = __slist_make_link(__pos, _M_create_node(*__first)); ++__first; } } void _M_insert_after_range(_Node_base* __pos, const value_type* __first, const value_type* __last) { while (__first != __last) { __pos = __slist_make_link(__pos, _M_create_node(*__first)); ++__first; } }#endif /* __STL_MEMBER_TEMPLATES */public: iterator insert_after(iterator __pos, const value_type& __x) { return iterator(_M_insert_after(__pos._M_node, __x)); } iterator insert_after(iterator __pos) { return insert_after(__pos, value_type()); } void insert_after(iterator __pos, size_type __n, const value_type& __x) { _M_insert_after_fill(__pos._M_node, __n, __x); }#ifdef __STL_MEMBER_TEMPLATES // We don't need any dispatching tricks here, because _M_insert_after_range // already does them. template <class _InIter> void insert_after(iterator __pos, _InIter __first, _InIter __last) { _M_insert_after_range(__pos._M_node, __first, __last); }#else /* __STL_MEMBER_TEMPLATES */ void insert_after(iterator __pos, const_iterator __first, const_iterator __last) { _M_insert_after_range(__pos._M_node, __first, __last); } void insert_after(iterator __pos, const value_type* __first, const value_type* __last) { _M_insert_after_range(__pos._M_node, __first, __last); }#endif /* __STL_MEMBER_TEMPLATES */ iterator insert(iterator __pos, const value_type& __x) { return iterator(_M_insert_after(__slist_previous(&_M_head, __pos._M_node), __x)); } iterator insert(iterator __pos) { return iterator(_M_insert_after(__slist_previous(&_M_head, __pos._M_node), value_type())); } void insert(iterator __pos, size_type __n, const value_type& __x) { _M_insert_after_fill(__slist_previous(&_M_head, __pos._M_node), __n, __x); } #ifdef __STL_MEMBER_TEMPLATES // We don't need any dispatching tricks here, because _M_insert_after_range // already does them. template <class _InIter> void insert(iterator __pos, _InIter __first, _InIter __last) { _M_insert_after_range(__slist_previous(&_M_head, __pos._M_node), __first, __last); }#else /* __STL_MEMBER_TEMPLATES */ void insert(iterator __pos, const_iterator __first, const_iterator __last) { _M_insert_after_range(__slist_previous(&_M_head, __pos._M_node), __first, __last); } void insert(iterator __pos, const value_type* __first, const value_type* __last) { _M_insert_after_range(__slist_previous(&_M_head, __pos._M_node), __first, __last); }#endif /* __STL_MEMBER_TEMPLATES */public: iterator erase_after(iterator __pos) { return iterator((_Node*) _M_erase_after(__pos._M_node)); } iterator erase_after(iterator __before_first, iterator __last) { return iterator((_Node*) _M_erase_after(__before_first._M_node, __last._M_node)); } iterator erase(iterator __pos) { return (_Node*) _M_erase_after(__slist_previous(&_M_head, __pos._M_node)); } iterator erase(iterator __first, iterator __last) { return (_Node*) _M_erase_after( __slist_previous(&_M_head, __first._M_node), __last._M_node); } void resize(size_type new_size, const _Tp& __x); void resize(size_type new_size) { resize(new_size, _Tp()); } void clear() { _M_erase_after(&_M_head, 0); }public: // Moves the range [__before_first + 1, __before_last + 1) to *this, // inserting it immediately after __pos. This is constant time. void splice_after(iterator __pos, iterator __before_first, iterator __before_last) { if (__before_first != __before_last) __slist_splice_after(__pos._M_node, __before_first._M_node, __before_last._M_node); } // Moves the element that follows __prev to *this, inserting it immediately // after __pos. This is constant time. void splice_after(iterator __pos, iterator __prev) { __slist_splice_after(__pos._M_node, __prev._M_node, __prev._M_node->_M_next); } // Linear in distance(begin(), __pos), and linear in __x.size(). void splice(iterator __pos, slist& __x) { if (__x._M_head._M_next) __slist_splice_after(__slist_previous(&_M_head, __pos._M_node), &__x._M_head, __slist_previous(&__x._M_head, 0)); } // Linear in distance(begin(), __pos), and in distance(__x.begin(), __i). void splice(iterator __pos, slist& __x, iterator __i) { __slist_splice_after(__slist_previous(&_M_head, __pos._M_node), __slist_previous(&__x._M_head, __i._M_node), __i._M_node); } // Linear in distance(begin(), __pos), in distance(__x.begin(), __first), // and in distance(__first, __last). void splice(iterator __pos, slist& __x, iterator __first, iterator __last) { if (__first != __last) __slist_splice_after(__slist_previous(&_M_head, __pos._M_node), __slist_previous(&__x._M_head, __first._M_node), __slist_previous(__first._M_node, __last._M_node)); }public: void reverse() { if (_M_head._M_next) _M_head._M_next = __slist_reverse(_M_head._M_next); } void remove(const _Tp& __val); void unique(); void merge(slist& __x); void sort(); #ifdef __STL_MEMBER_TEMPLATES template <class _Predicate> void remove_if(_Predicate __pred); template <class _BinaryPredicate> void unique(_BinaryPredicate __pred); template <class _StrictWeakOrdering> void merge(slist&, _StrictWeakOrdering); template <class _StrictWeakOrdering> void sort(_StrictWeakOrdering __comp); #endif /* __STL_MEMBER_TEMPLATES */};template <class _Tp, class _Alloc>slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x){ if (&__x != this) { _Node_base* __p1 = &_M_head; _Node* __n1 = (_Node*) _M_head._M_next; const _Node* __n2 = (const _Node*) __x._M_head._M_next; while (__n1 && __n2) { __n1->_M_data = __n2->_M_data; __p1 = __n1; __n1 = (_Node*) __n1->_M_next; __n2 = (const _Node*) __n2->_M_next; } if (__n2 == 0) _M_erase_after(__p1, 0); else _M_insert_after_range(__p1, const_iterator((_Node*)__n2), const_iterator(0)); } return *this;}template <class _Tp, class _Alloc>void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) { _Node_base* __prev = &_M_head; _Node* __node = (_Node*) _M_head._M_next; for ( ; __node != 0 && __n > 0 ; --__n) { __node->_M_data = __val; __prev = __node; __node = (_Node*) __node->_M_next; } if (__n > 0) _M_insert_after_fill(__prev, __n, __val); else _M_erase_after(__prev, 0);}#ifdef __STL_MEMBER_TEMPLATEStemplate <class _Tp, class _Alloc> template <class _InputIter>voidslist<_Tp, _Alloc>::_M_assign_dispatch(_InputIter __first, _InputIter __last, __false_type){ _Node_base* __prev = &_M_head; _Node* __node = (_Node*) _M_head._M_next; while (__node != 0 && __first != __last) { __node->_M_data = *__first; __prev = __node; __node = (_Node*) __node->_M_next; ++__first; } if (__first != __last) _M_insert_after_range(__prev, __first, __last); else _M_erase_after(__prev, 0);}#endif /* __STL_MEMBER_TEMPLATES */template <class _Tp, class _Alloc>inline bool operator==(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2){ typedef typename slist<_Tp,_Alloc>::const_iterator const_iterator; const_iterator __end1 = _SL1.end(); const_iterator __end2 = _SL2.end(); const_iterator __i1 = _SL1.begin(); const_iterator __i2 = _SL2.begin(); while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) { ++__i1; ++__i2; } return __i1 == __end1 && __i2 == __end2;}template <class _Tp, class _Alloc>inline booloperator<(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2){ return lexicographical_compare(_SL1.begin(), _SL1.end(), _SL2.begin(), _SL2.end());}#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDERtemplate <class _Tp, class _Alloc>inline bool operator!=(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2) { return !(_SL1 == _SL2);}template <class _Tp, class _Alloc>inline bool operator>(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2) { return _SL2 < _SL1;}template <class _Tp, class _Alloc>inline bool operator<=(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2) { return !(_SL2 < _SL1);}template <class _Tp, class _Alloc>inline bool operator>=(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2) { return !(_SL1 < _SL2);}template <class _Tp, class _Alloc>inline void swap(slist<_Tp,_Alloc>& __x, slist<_Tp,_Alloc>& __y) { __x.swap(__y);}#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */template <class _Tp, class _Alloc>void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x){ _Node_base* __cur = &_M_head; while (__cur->_M_next != 0 && __len > 0) { --__len; __cur = __cur->_M_next; } if (__cur->_M_next) _M_erase_after(__cur, 0); else _M_insert_after_fill(__cur, __len, __x);}template <class _Tp, class _Alloc>void slist<_Tp,_Alloc>::remove(const _Tp& __val){ _Node_base* __cur = &_M_head; while (__cur && __cur->_M_next) { if (((_Node*) __cur->_M_next)->_M_data == __val) _M_erase_after(__cur); else __cur = __cur->_M_next; }}template <class _Tp, class _Alloc> void slist<_Tp,_Alloc>::unique(){ _Node_base* __cur = _M_head._M_next; if (__cur) { while (__cur->_M_next) { if (((_Node*)__cur)->_M_data == ((_Node*)(__cur->_M_next))->_M_data) _M_erase_after(__cur); else __cur = __cur->_M_next; } }}template <class _Tp, class _Alloc>void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x){ _Node_base* __n1 = &_M_head; while (__n1->_M_next && __x._M_head._M_next) { if (((_Node*) __x._M_head._M_next)->_M_data < ((_Node*) __n1->_M_next)->_M_data) __slist_splice_after(__n1, &__x._M_head, __x._M_head._M_next); __n1 = __n1->_M_next; } if (__x._M_head._M_next) { __n1->_M_next = __x._M_head._M_next; __x._M_head._M_next = 0; }}template <class _Tp, class _Alloc>void slist<_Tp,_Alloc>::sort(){ if (_M_head._M_next && _M_head._M_next->_M_next) { slist __carry; slist __counter[64]; int __fill = 0; while (!empty()) { __slist_splice_after(&__carry._M_head, &_M_head, _M_head._M_next); int __i = 0; while (__i < __fill && !__counter[__i].empty()) { __counter[__i].merge(__carry); __carry.swap(__counter[__i]); ++__i; } __carry.swap(__counter[__i]); if (__i == __fill) ++__fill; } for (int __i = 1; __i < __fill; ++__i) __counter[__i].merge(__counter[__i-1]); this->swap(__counter[__fill-1]); }}#ifdef __STL_MEMBER_TEMPLATEStemplate <class _Tp, class _Alloc> template <class _Predicate>void slist<_Tp,_Alloc>::remove_if(_Predicate __pred){ _Node_base* __cur = &_M_head; while (__cur->_M_next) { if (__pred(((_Node*) __cur->_M_next)->_M_data)) _M_erase_after(__cur); else __cur = __cur->_M_next; }}template <class _Tp, class _Alloc> template <class _BinaryPredicate> void slist<_Tp,_Alloc>::unique(_BinaryPredicate __pred){ _Node* __cur = (_Node*) _M_head._M_next; if (__cur) { while (__cur->_M_next) { if (__pred(((_Node*)__cur)->_M_data, ((_Node*)(__cur->_M_next))->_M_data)) _M_erase_after(__cur); else __cur = (_Node*) __cur->_M_next; } }}template <class _Tp, class _Alloc> template <class _StrictWeakOrdering>void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x, _StrictWeakOrdering __comp){ _Node_base* __n1 = &_M_head; while (__n1->_M_next && __x._M_head._M_next) { if (__comp(((_Node*) __x._M_head._M_next)->_M_data, ((_Node*) __n1->_M_next)->_M_data)) __slist_splice_after(__n1, &__x._M_head, __x._M_head._M_next); __n1 = __n1->_M_next; } if (__x._M_head._M_next) { __n1->_M_next = __x._M_head._M_next; __x._M_head._M_next = 0; }}template <class _Tp, class _Alloc> template <class _StrictWeakOrdering> void slist<_Tp,_Alloc>::sort(_StrictWeakOrdering __comp){ if (_M_head._M_next && _M_head._M_next->_M_next) { slist __carry; slist __counter[64]; int __fill = 0; while (!empty()) { __slist_splice_after(&__carry._M_head, &_M_head, _M_head._M_next); int __i = 0; while (__i < __fill && !__counter[__i].empty()) { __counter[__i].merge(__carry, __comp); __carry.swap(__counter[__i]); ++__i; } __carry.swap(__counter[__i]); if (__i == __fill) ++__fill; } for (int __i = 1; __i < __fill; ++__i) __counter[__i].merge(__counter[__i-1], __comp); this->swap(__counter[__fill-1]); }}#endif /* __STL_MEMBER_TEMPLATES */#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)#pragma reset woff 1174#pragma reset woff 1375#endif__STL_END_NAMESPACE #endif /* __SGI_STL_INTERNAL_SLIST_H */// Local Variables:// mode:C++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -