Title says it all, under what circumstances would the default constructor for std::vector require a copy constructor for the elements and not accept only a move constructor? I am explicitly deleting the copy constructor and explicitly defaulting the move constructor using VS2017.
Asked
Active
Viewed 218 times
1 Answers
0
Before C++11, std::vector
required that the element type is copy-constructible and copy-assignable.
From C++11 onwards the type requirements for the element type of a std::vector
have been weakened, and std::vector
now only requires the element type to be complete (until C++17) and erasable by the given allocator.
Calling certain member functions however, might impose additional requirements on the element type. The default constructor is not one of them, though.
That means that the element type doesn't need to have a copy-constructor for the vector to be default constructible - in fact you can default construct a std::vector
with an element type that is not constructible at all (see here).

Corristo
- 4,911
- 1
- 20
- 36