Suppose I have a class called vector that supports some internal dynamic array of type T allocated by std::allocator<T>. . Now I am building a vector type U , and later I want to use move semantics so that I can use the memory it consumes for vector type T , for example:
vector<unsigned> u(512);
Is it possible to use the memory allocated by the U allocator in the T move constructor, and then free it with the T allocator? If so, what should I do to ensure that this operation is safe? I assume that I should first call allocator.destroy() for each element of the internal array U , using U allocator.
source share