由于list容器的特殊实现,所以list容器实现了自己的erase函数和remove函数。
erase函数的函数声明:
可以看到函数的参数是由迭代器给出的。由迭代器给出删除的位置或者区间。
1) Removes from the list container either a single element (position) or a range of elements ([first,last)).
2) This effectively reduces the container size by the number of elements removed, which are destroyed.
remove函数的函数声明
可以看出,参数不是迭代器类型的,而是value_type类型的,目的是为了删除容器中的特定值。
1) Removes from the container all the elements that compare equal to val. This calls the destructor of these objects and reduces the container size by the number of elements removed.
2) Unlike member function list::erase, which erases elements by their position (using an iterator), this function (list::remove) removes elements by their value.