I’ve read in several places that std::vector requires it’s template argument to be default constructible. Today I just tried it with one of my classes that has a deleted default constructor, and to my surprise it seems to be working just fine (with std::vector’s default constructor). Is this portable behavior, or is this an implementation detail of gcc’s STL and should I assume vector to require it’s template argument to be default constructible?
I’ve read in several places that std::vector requires it’s template argument to be default
Share
The requirement in C++03 is that types being stored in a container be
CopyConstructibleandAssignable(see §23.1 Container Requirements). However, in C++11 these requirements are relaxed, and tend to apply to the operations performed on the container. So a simple default construction has no requirements (see teble 96, §23.1 in C++11 standard).As soon as you try to copy a vector, or insert elements into it, you will meet the
CopyInsertable,CopyAssignable,EmplaceConstructible,MoveInsertable,MoveAssignableetc. requirements