How to erase elements from boost::ptr_vector

前端 未结 6 1306
清歌不尽
清歌不尽 2021-01-12 13:52

So I\'m trying to get rid of my std::vector\'s by using boost::ptr_vector. Now I\'m trying to remove an element from one, and have the removed element deleted as well. The m

6条回答
  •  再見小時候
    2021-01-12 14:46

    Curious thing: STL::vector<> is a Random Access Container, meaning that it uses Random Access Iterators.

    So vec.erase(vec.begin()+N) will remove the element at index N.

    Note that doing so breaks the whole iterator meme and you can no longer trivially switch between vectors and lists...

提交回复
热议问题