C ++ 11では、std :: vectorには、vector(size_type n)
デフォルトで構築n
アイテムを配置するコンストラクターがあります。これは、デフォルトの構築可能、移動可能、コピー不可能なクラスで使用できます。
ただし、他のすべてのベクトルコンストラクターとは異なり、アロケーターを使用するバリアントはありません。私は次のことに頼りました。
// Foo is default constructible and moveable, but not copyable
const int n = 10; // Want 10 default constructed Foos
std::vector<Foo, CustomAllocator> foos(allocator);
foos.reserve(n);
for (int i = 0; i < n; ++i)
foos.emplace_back();
これを達成するためのより良い方法はありますか?vector(size_type n, const Allocator& alloc)
規格から除外された特別な理由はありますか?