Why is that the single parameter constructor of std::list<T>
requires T
to be a default-constructible type? I mean the following code does not compile.
struct Foo { // does not have default constructor.
Foo (int i) {}
}
int main(void) {
std::list<Foo> l(10);
}
It seems possible to use the construct and destroy idioms as they have already done in the std::vector, albeit with more book-keeping the list class.
On a related note, why not have the capacity function in list? You can argue that such a function would pay memory allocation cost up-front and eliminate the overhead later on as you push_back
objects. At least it will make the interfaces of two STL sequence containers slightly more consistent.