According to eg https://en.cppreference.com/w/cpp/container/vector/erase the parameters to std::vector::erase
were in C++11 changed from iterator
to const_iterator
.
This is surprising; logically, the container does have to change the data pointed to by those iterators, and indeed when I implemented my own vector class, the compiler complained that I was calling memmove
with a const pointer; I fixed it by changing the parameters back to iterator
.
What's the logic behind making them const_iterator
?
The iterator just says where. The vector is non-const, and is from which it is erased.
This lets you find the location to be erased in a cost manner, and only when you actually erase it do you need a non const container.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.