Why copy constructor is called in std::vector’s initializer list?

It’s specifically because you use an initializer list that the copy-constructor is used. The initializer list is initialized with a copy of the object, and then passed to the vector.

If you read the linked reference, from C++14 it even explicitly say

… each element is copy-initialized … from the corresponding element of the original initializer list

Emphasis mine

Leave a Comment