【发布时间】:2012-05-11 00:49:32
【问题描述】:
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 类型的对象。
【问题讨论】:
标签: c++ c++11 allocation allocator