About std::vector

Why 'vector' doesn't store addresses? If so, when calling "v.erase( v.begin() );", it wouldn't have to call X move/copy constructors (if the template is a class).

What do you think?
What you are talking about sounds like boost::ptr_vector

You could also get similar functionality by having a vector of unique_ptrs.
std::vector<std::unique_ptr<T>> v;

You don't always want the vector to store pointers. It depends on what is being stored and how you use the vector.

If the vector stored pointers it would have to dynamically allocate the elements which could make things slower and less cache friendly. It also has some memory overhead. Sometimes you want the elements in the vector to be stored contiguous in memory.
A vector is designed to:
1. Minimize random access time.
2. Cheaply push and pop on the back.
If you need to pop from the front at all, then a vector just isn't the data structure to use there. std::deque sacrifices a tiny bit of random access performance in exchange for allowing cheaply popping and pushing on either end.
Topic archived. No new replies allowed.