_slist.h
来自「stl的源码」· C头文件 代码 · 共 915 行 · 第 1/3 页
H
915 行
}#endif /*_STLP_DONT_SUP_DFLT_PARAM*/ void insert_after(iterator __pos, size_type __n, const value_type& __x) { _M_insert_after_fill(__pos._M_node, __n, __x); }#if defined (_STLP_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) {#else /* _STLP_MEMBER_TEMPLATES */ void insert_after(iterator __pos, const value_type* __first, const value_type* __last) { _M_insert_after_range(__pos._M_node, __first, __last); } void insert_after(iterator __pos, const_iterator __first, const_iterator __last) {#endif /* _STLP_MEMBER_TEMPLATES */ _M_splice_after_range(__pos._M_node, __first, __last); }#if !defined (_STLP_DONT_SUP_DFLT_PARAM) iterator insert(iterator __pos, const value_type& __x = _Tp()) {#else iterator insert(iterator __pos, const value_type& __x) {#endif /*_STLP_DONT_SUP_DFLT_PARAM*/ return iterator(_M_insert_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), __x)); }#if defined (_STLP_DONT_SUP_DFLT_PARAM) iterator insert(iterator __pos) { return iterator(_M_insert_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), _STLP_DEFAULT_CONSTRUCTED(_Tp))); }#endif /*_STLP_DONT_SUP_DFLT_PARAM*/ void insert(iterator __pos, size_type __n, const value_type& __x) { _M_insert_after_fill(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), __n, __x); }#if defined (_STLP_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) {#else /* _STLP_MEMBER_TEMPLATES */ void insert(iterator __pos, const value_type* __first, const value_type* __last) { _M_insert_after_range(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), __first, __last); } void insert(iterator __pos, const_iterator __first, const_iterator __last) {#endif /* _STLP_MEMBER_TEMPLATES */ _M_splice_range(__pos._M_node, __first, __last); }public: iterator erase_after(iterator __pos) { return iterator(this->_M_erase_after(__pos._M_node)); } iterator erase_after(iterator __before_first, iterator __last) { return iterator(this->_M_erase_after(__before_first._M_node, __last._M_node)); } iterator erase(iterator __pos) { return iterator(this->_M_erase_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node))); } iterator erase(iterator __first, iterator __last) { return iterator(this->_M_erase_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __first._M_node), __last._M_node)); }#if !defined (_STLP_DONT_SUP_DFLT_PARAM) void resize(size_type new_size, const value_type& __x = _Tp());#else void resize(size_type new_size, const value_type& __x);#endif /*_STLP_DONT_SUP_DFLT_PARAM*/#if defined (_STLP_DONT_SUP_DFLT_PARAM) void resize(size_type new_size) { resize(new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }#endif /*_STLP_DONT_SUP_DFLT_PARAM*/ void clear() { this->_M_erase_after(&this->_M_head._M_data, 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, _Self& __x, iterator __before_first, iterator __before_last) { if (__before_first != __before_last) { if (this->get_allocator() == __x.get_allocator()) { _STLP_PRIV _Sl_global_inst::__splice_after(__pos._M_node, __before_first._M_node, __before_last._M_node); } else { this->insert_after(__pos, iterator(__before_first._M_node->_M_next), iterator(__before_last._M_node->_M_next)); __x.erase_after(__before_first, ++__before_last); } } } // Moves the element that follows __prev to *this, inserting it immediately // after __pos. This is constant time. void splice_after(iterator __pos, _Self& __x, iterator __prev) { if (this->get_allocator() == __x.get_allocator()) { _STLP_PRIV _Sl_global_inst::__splice_after(__pos._M_node, __prev._M_node, __prev._M_node->_M_next); } else { this->insert_after(__pos, __STATIC_CAST(_Node*, __prev._M_node->_M_next)->_M_data); __x.erase_after(__prev); } } // Removes all of the elements from the list __x to *this, inserting // them immediately after __pos. __x must not be *this. Complexity: // linear in __x.size(). void splice_after(iterator __pos, _Self& __x) { if (this->get_allocator() == __x.get_allocator()) _STLP_PRIV _Sl_global_inst::__splice_after(__pos._M_node, &__x._M_head._M_data); else { this->insert_after(__pos, __x.begin(), __x.end()); __x.clear(); } } // Linear in distance(begin(), __pos), and linear in __x.size(). void splice(iterator __pos, _Self& __x) { if (__x._M_head._M_data._M_next) { if (this->get_allocator() == __x.get_allocator()) { _STLP_PRIV _Sl_global_inst::__splice_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), &__x._M_head._M_data, _STLP_PRIV _Sl_global_inst::__previous(&__x._M_head._M_data, 0)); } else { insert(__pos, __x.begin(), __x.end()); __x.clear(); } } } // Linear in distance(begin(), __pos), and in distance(__x.begin(), __i). void splice(iterator __pos, _Self& __x, iterator __i) { if (this->get_allocator() == __x.get_allocator()) { _STLP_PRIV _Sl_global_inst::__splice_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), _STLP_PRIV _Sl_global_inst::__previous(&__x._M_head._M_data, __i._M_node), __i._M_node); } else { insert(__pos, *__i); __x.erase(__i); } } // Linear in distance(begin(), __pos), in distance(__x.begin(), __first), // and in distance(__first, __last). void splice(iterator __pos, _Self& __x, iterator __first, iterator __last) { if (__first != __last) { if (this->get_allocator() == __x.get_allocator()) { _STLP_PRIV _Sl_global_inst::__splice_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), _STLP_PRIV _Sl_global_inst::__previous(&__x._M_head._M_data, __first._M_node), _STLP_PRIV _Sl_global_inst::__previous(__first._M_node, __last._M_node)); } else { insert(__pos, __first, __last); __x.erase(__first, __last); } } }public: void reverse() { if (this->_M_head._M_data._M_next) this->_M_head._M_data._M_next = _STLP_PRIV _Sl_global_inst::__reverse(this->_M_head._M_data._M_next); } void remove(const _Tp& __val); void unique() { _STLP_PRIV _Slist_unique(*this, equal_to<value_type>()); } void merge(_Self& __x) { _STLP_PRIV _Slist_merge(*this, __x, less<value_type>()); } void sort() { _STLP_PRIV _Slist_sort(*this, less<value_type>()); }#if defined (_STLP_MEMBER_TEMPLATES) template <class _Predicate> void remove_if(_Predicate __pred) { _Node_base* __cur = &this->_M_head._M_data; while (__cur->_M_next) { if (__pred(__STATIC_CAST(_Node*, __cur->_M_next)->_M_data)) this->_M_erase_after(__cur); else __cur = __cur->_M_next; } } template <class _BinaryPredicate> void unique(_BinaryPredicate __pred) { _STLP_PRIV _Slist_unique(*this, __pred); } template <class _StrictWeakOrdering> void merge(_Self& __x, _StrictWeakOrdering __comp) { _STLP_PRIV _Slist_merge(*this, __x, __comp); } template <class _StrictWeakOrdering> void sort(_StrictWeakOrdering __comp) { _STLP_PRIV _Slist_sort(*this, __comp); }#endif /* _STLP_MEMBER_TEMPLATES */};#if defined (slist)# undef slist_STLP_MOVE_TO_STD_NAMESPACE#endif_STLP_END_NAMESPACE#if !defined (_STLP_LINK_TIME_INSTANTIATION)# include <stl/_slist.c>#endif#if defined (_STLP_USE_PTR_SPECIALIZATIONS)# include <stl/pointers/_slist.h>#endif#if defined (_STLP_DEBUG)# include <stl/debug/_slist.h>#endif_STLP_BEGIN_NAMESPACEtemplate <class _Tp, class _Alloc>inline bool _STLP_CALLoperator == (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;}#define _STLP_EQUAL_OPERATOR_SPECIALIZED#define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc>#define _STLP_TEMPLATE_CONTAINER slist<_Tp, _Alloc>#include <stl/_relops_cont.h>#undef _STLP_TEMPLATE_CONTAINER#undef _STLP_TEMPLATE_HEADER#undef _STLP_EQUAL_OPERATOR_SPECIALIZED#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)# if !defined (_STLP_NO_MOVE_SEMANTIC)template <class _Tp, class _Alloc>struct __move_traits<slist<_Tp, _Alloc> > { typedef __true_type implemented; typedef typename __move_traits<_Alloc>::complete complete;};# endif// Specialization of insert_iterator so that insertions will be constant// time rather than linear time.template <class _Tp, class _Alloc>class insert_iterator<slist<_Tp, _Alloc> > {protected: typedef slist<_Tp, _Alloc> _Container; _Container* _M_container; typename _Container::iterator _M_iter;public: typedef _Container container_type; typedef output_iterator_tag iterator_category; typedef void value_type; typedef void difference_type; typedef void pointer; typedef void reference; insert_iterator(_Container& __x, typename _Container::iterator __i) : _M_container(&__x) { if (__i == __x.begin()) _M_iter = __x.before_begin(); else _M_iter = __x.previous(__i); } insert_iterator<_Container>& operator = (const typename _Container::value_type& __val) { _M_iter = _M_container->insert_after(_M_iter, __val); return *this; } insert_iterator<_Container>& operator*() { return *this; } insert_iterator<_Container>& operator++() { return *this; } insert_iterator<_Container>& operator++(int) { return *this; }};#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */_STLP_END_NAMESPACE#endif /* _STLP_INTERNAL_SLIST_H */// Local Variables:// mode:C++// End:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?