Assuming that a vector contains an array internally of std::aligned_storage
instances that actually contain elements of the type the vector is templated on if the aligned_storage
instance is in use.
When the vector has to allocate a new block of memory and move all its elements, why does it invoke the move constructor of each element in use and then destroy the old element? Why not just copy over all the bytes byte by byte and just delete the old array without calling destructors? This would make the new array an exact copy of the old array without the overhead of moving and destroying elements.
Maybe I'm a little tired and am missing something really basic. But I cannot think of a reason why this would not work.