When I initialize a STL container such as a list< vector<char> > using e.g. my_list.push_back(vector<char>(5000, 'T')) is this copied after construction? Or does the compiler invoke the constructor inside list< vector<char> > itself?
When I initialize a STL container such as a list< vector<char> > using e.g.
Share
In C++03
push_backis defined asvoid push_back(const T& x);. That means that you are constructing avectorand a const reference to such temporal is being passed to thelist. Then thelistinternally invokes the copy constructor in order to store a copy of such element.In C++11 there is an extra definition for
void push_back(T&& x);that takes an rvalue reference to your temporalvector, and would result in the move constructor being called internally to initialize the copy held by thelist.