Let's say I'm writing a custom vector using the std::allocator to wrap new and delete.
When the number of elements exceed the vector's capacity, I would like to reallocate the buffer to something larger. I can achieve this easily by calling realloc(). I don't want to do this though because I thought the responsibility of allocation/deallocation should reside in the allocator.
Yet, looking at std::allocator's interface, I don't see how I could do a reallocation. There are only methods for:
T* allocate( std::size_t n );
void deallocate( T* p, std::size_t n );
Should I be calling allocator::allocate and then allocator::deallocate instead of just realloc? Is that as efficient? It must be what std::vector is doing as well. Why does std::allocator not provide a reallocate function?