8
std::allocator
的construct
和destroy
成員函數參數的元素的類型來構造:爲什麼std :: allocator :: construct和std :: allocator :: 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
類型的對象。