How would I efficiently resize an array allocated using some standards-conforming C++ allocator? I know that no facilities for reallocation are provided in the C++ alloctor interface, but did the C++11 revision enable us to work with them more easily? Suppose that I have a class vec
with a copy-assignment operator foo& operator=(const foo& x)
defined. If x.size() > this->size()
, I'm forced to
- Call allocator.destroy() on all elements in the internal storage of
foo
. - Call allocator.deallocate() on the internal storage of
foo.
- Reallocate a new buffer with enough room for
x.size()
elements. - Use std::uninitialized_copy to populate the storage.
Is there some way that I more easily reallocate the internal storage of foo
without having to go through all of this? I could provide an actual code sample if you think that it would be useful, but I feel that it would be unnecessary here.