121
General / Re: Deciding which Container to use for a Manager Class.
« on: October 31, 2012, 05:16:38 am »Quote
Vectors are very fast at iterating from the start to end, but removing something in the middle can be heavy. Consider adding are removing instances nearly every step. (Obviously, there are very few times when this is even a good idea, but I know a vector is not the best container for this scenario.)
A vector or deque should be considered the container of choice until you know that you need the qualities of another container.
Removing something from the middle of a vector can be quite cheap if the element is say, a pointer, and the relative order of elements in the vector isn't important. Just swap it with the back one and erase the end (or resize if you prefer.) And, you won't find faster insertion/deletion than at the ass-end of a vector or either end of a deque.