A great deal here depends on what he means by a "dynamic array". Most people mean something where the memory is allocated with array-new and freed with array-delete. If that's the intent here, then having qualities on a par with std::vector
simply isn't possible.
The reason is fairly simple: std::vector
routinely allocates a chunk of memory larger than necessary to hold the number of elements currently being stored. It then constructs objects in that memory as needed to expand. With array-new, however, you have no choice -- you're allocating an array of objects, so if you allocate space for (say) 100 objects, you end up with 100 objects being created in that space (immediately). It simply has no provision for having a buffer some part of which contains real objects, and another part of which is just plain memory, containing nothing.
I suppose if yo want to stretch a point, it's possible to imitate std::vector
and still allocate the space with array-new. To do it, you just have to allocate an array of char
, and then use placement new
to create objects in that raw memory space. This allows pretty much the same things as std::vector
, because it is nearly the same thing as std::vector
. We're still missing a (potential) level of indirection though -- std::vector
actually allocates memory via an Allocator object so you can change exactly how it allocates its raw memory (by default it uses std::allocator<T>
, which uses operator new
, but if you wanted to, you could actually write an allocator that would use new char[size]
, though I can't quite imagine why you would).
You could, of course, write your dynamic array to use an allocator object as well. At that point, for all practical purposes you've just reinvented std::vector
under a (presumably) new name. In that case, @sbi is still right: the mere fact that it's not standardized means it's still missing one of the chief qualities of std:::vector
-- the quality of being standardized and already known by everybody who knows C++. Even without that, though, we have to stretch the phrase "dynamic array" to (and I'd posit, beyond) the breaking point to get the same qualities as std::vector
, even if we ignore standardization.