stl 源代码疑问# Programming - 葵花宝典
c*z
1 楼
在list中有两个操作insert和erase,它们都是返回一个iterator的类型,可是在代码
中返回的方式不同,如下:
在insert中:
iterator insert(iterator __position, const _Tp& __x) {
_Node* __tmp = _M_create_node(__x);
__tmp->_M_next = __position._M_node;
__tmp->_M_prev = __position._M_node->_M_prev;
__position._M_node->_M_prev->_M_next = __tmp;
__position._M_node->_M_prev = __tmp;
return __tmp;
}
在erase中:
iterator erase(iterator __position) {
_List_node_base* __next_node = __position._M_node->_M_next;
_List_nod
中返回的方式不同,如下:
在insert中:
iterator insert(iterator __position, const _Tp& __x) {
_Node* __tmp = _M_create_node(__x);
__tmp->_M_next = __position._M_node;
__tmp->_M_prev = __position._M_node->_M_prev;
__position._M_node->_M_prev->_M_next = __tmp;
__position._M_node->_M_prev = __tmp;
return __tmp;
}
在erase中:
iterator erase(iterator __position) {
_List_node_base* __next_node = __position._M_node->_M_next;
_List_nod