§23.2.4.6 void resize(size_type sz, T c = T()); 6 Effects: if (sz > size()) insert(end(), sz-size(), c); else if (sz < size()) erase(begin()+sz, end()); else ; //do nothing
§23.2.4.3.2 iterator erase(iterator position); iterator erase(iterator first, iterator last); 3 Effects: Invalidates all the iterators and references after the point of the erase. 4 Complexity: The destructor of T is called the number of times equal to the number of the elements erased, but the assignment operator of T is called the number of times equal to the number of elements in the vector after the erased elements. 5 Throws: Nothing unless an exception is thrown by the copy constructor or assignment operator of T.
まぁ、 for (std::vector<int>::const_iterator it = v.begin(); it != v.end(); ++it) { sum += * it; } くらいなら for (int ic = 0; ic < end; ++ic) { sum += a[ic]; } と同じ程度のコードを吐くコンパイラくらいいくらでもあるだろ。