If I construct an empty std::vector
using the default constructor (and the default allocator), can it throw an exception?
In general, allocating space for the elements of a container can throw an exception (which would be a std::bad_alloc
). But the default constructor of a std::vector
does not need to allocate any such space; it can lazily allocate some space on the first insertion or assignment. But does the C++ standard require that it does not throw exceptions (implying lazy allocation, or catching std::bad_alloc
and then falling back to lazy allocation)?