Difference between std::remove and erase for vector?

后端 未结 8 1902
失恋的感觉
失恋的感觉 2020-12-12 18:42

I have a doubt that I would like to clarify in my head. I am aware of the different behavior for std::vector between erase and std::remove

8条回答
  •  感情败类
    2020-12-12 19:36

    I think it has to do with needing direct access to the vector itself to be able to resize it. std::remove only has access to the iterators, so it has no way of telling the vector "Hey, you now have fewer elements".

    See yves Baumes answer as to why std::remove is designed this way.

提交回复
热议问题