3 ms·
The vector is initialized with 500000 widget objects. The size and capacity of the vector are equal. The following while loop is never executed. >> while (vw.s
by oldsklgdfth 10y ago
The vector is initialized with 500000 widget objects. The size and capacity of the vector are equal. The following while loop is never executed.
>> while (vw.size() < vw.capacity())
>> vw.push_back(Widget());
In the situation that the vector is not initialized with elements and populated in a loop the time for a single push_back is equal. I think this is because there is no need for a resize.
>> vector<Widget> vw;
>> for(int i = 0; i < 500000; i++) {
>> vw.push_back(Widget());
>> }
Does this illustrate how fast a vector of objects can be copied/resized using move semantics?