std::allocator
的construct
和destroy
成员函数是基于要构造的元素类型进行参数化的:
template<class T>
class allocator
{
public:
typedef T value_type;
typedef T* pointer;
template<class U, class... Args>
void construct(U *p, Args&&... args);
template<class U>
void destroy(U *p);
...
};
为什么不使用value_type*
或pointer
?这样做的理由是什么?看起来,allocator<T>
应该只知道如何构造或销毁类型T
的对象。