STL vector vs map erase

前端 未结 5 1910
暖寄归人
暖寄归人 2020-12-29 08:43

In the STL almost all containers have an erase function. The question I have is in a vector, the erase function returns an iterator pointing to the next element in the vect

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 09:13

    erase returns an iterator in C++11. This is due to defect report 130:

    Table 67 (23.1.1) says that container::erase(iterator) returns an iterator. Table 69 (23.1.2) says that in addition to this requirement, associative containers also say that container::erase(iterator) returns void. That's not an addition; it's a change to the requirements, which has the effect of making associative containers fail to meet the requirements for containers.

    The standards committee accepted this:

    the LWG agrees the return type should be iterator, not void. (Alex Stepanov agrees too.)

    (LWG = Library Working Group).

提交回复
热议问题