STL中一个关于形参的有关问题

STL中一个关于形参的问题
本帖最后由 gigglesun 于 2014-02-26 12:57:11 编辑

//this is the code from stl_list.h in SGI STL, splice is a member function in list

template <class _Tp, class _Alloc>
class _List_base 
{
public:
  typedef _Alloc allocator_type;
  allocator_type get_allocator() const { return allocator_type(); }

  _List_base(const allocator_type&) {
    _M_node = _M_get_node();
    _M_node->_M_next = _M_node;
    _M_node->_M_prev = _M_node;
  }
  ~_List_base() {
    clear();
    _M_put_node(_M_node);
  }

  void clear();

protected:
  typedef simple_alloc<_List_node<_Tp>, _Alloc> _Alloc_type;
  _List_node<_Tp>* _M_get_node() { return _Alloc_type::allocate(1); }
  void _M_put_node(_List_node<_Tp>* __p) { _Alloc_type::deallocate(__p, 1); }

protected:
  _List_node<_Tp>* _M_node;
};

template <class _Tp, class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
class list : protected _List_base<_Tp, _Alloc> {
    public:
      void splice(iterator __position, list& __x) {
        if (!__x.empty()) 
          this->transfer(__position, __x.begin(), __x.end());
      }
      void splice(iterator __position, list&, iterator __i) {
        iterator __j = __i;
        ++__j;
        if (__position == __i || __position == __j) return;
        this->transfer(__position, __i, __j);
      }

      // 形参list&的作用?
      void splice(iterator __position,list&, iterator __first, iterator __last) {
        if (__first != __last) 
          this->transfer(__position, __first, __last);
      }
      void remove(const _Tp& __value);
      void unique();
      void merge(list& __x);
      void reverse();
      void sort();
    }


SGI STL源码中的一段代码,splice函数中,为什么list&出现在形参列表中,函数体却没有用它,有什么作用?
------解决方案--------------------
这篇博文很好的回答你的问题STL中一个关于形参的有关问题
http://www.cnblogs.com/allanyz/archive/2008/09/23/1297281.html