以下のコード リストのように、任意のアロケーターを使用して割り当てられたプリミティブ型の配列に対して allocator.construct() を呼び出す必要がありますか? クラスは、割り当てられたメモリを特定の値に初期化する必要がないため、新しく割り当てられたメモリのチャンクで allocator.construct() を呼び出す必要はないように思えます。配列が常にプリミティブ型で構成されている場合、このメソッドを呼び出さないことに危険はありますか?
template <class T, template <class> class Allocator = std::allocator>
class foo
{
public:
typedef Allocator<T> allocator;
typedef typename allocator::pointer pointer;
private:
unsigned size_;
allocator alloc_;
pointer t_;
public:
foo(unsigned n) throw(std::bad_alloc) : size_(n), alloc_(),
t_(alloc_.allocate(n))
{
// Note that I do not call alloc_.construct() here.
}
~foo() { alloc_.deallocate(t_, size_); }
};