I need to handle various (varied at runtime) amount of pointers in a vector. That is, I need sometimes to remove certain elements, i.e., as I understood, there will be some "empty slots" in the vector. 1./ What is the method (with good performance) to make "compact" the vector again (after "remove") 2./ I want to use binary search (for speed). I did not see a template, that returns the index of the element, rather than returning a boolean if an element was found, only hand-coded methods. 3./ Are there any risks if I use (for sorting) uint casting, and compacting the elements? (I am working with SystemC, that as far as I understand, uses one thread only.)
resize()
to shrink the size after you remove the elements. But using erase()
method will do the resizing for you.std::map
which offers find()
method that you can quickly search for an element and get it's index.