#include <iostream>
#include <memory>
#include <vector>
template <typename T>
class TrackingAllocator : public std::allocator<T> {
public:
using size_type = size_t;
using pointer = T*;
using const_pointer = const T*;
template <typename U>
struct rebind {
typedef TrackingAllocator<U> other;
};
pointer allocate(size_type n, const void* hint = 0) {
std::cout << "Allocating " << n << " objects\n";
return std::allocator<T>::allocate(n, hint);
}
void deallocate(pointer p, size_type n) {
std::cout << "Deallocating " << n << " objects\n";
std::allocator<T>::deallocate(p, n);
}
};
int main() {
std::vector<int, TrackingAllocator<int>> v;
for (int i = 0; i < 10; ++i) {
v.push_back(i);
}
return 0;
}