[Effective-cpp] Item 1: Uses and Abuses of vector

Lois Goldthwaite lois at loisgoldthwaite.com
Wed Oct 27 12:14:20 EDT 2004


On Wednesday 27 October 2004 15:54, White Wolf wrote:
> effective-cpp-bounces at accu.org wrote:
> > OOPS!!!  I meant to write "I would NOT use . . ."  sorry about that.
> >
> >> On another point raised, I would use this sort of loop for a vector
> >> that I intend to modify, especially if the modification involved
> >> removing items.  I learned this the difficult way, once trying to
> >> iterate through a vector to remove elements, and at times, the
> >> removal would blow the "end iterator" away.
>
> I believe that the problem is that in real life "I" (you - in your text)
> means the 50 developers at any given time working on a project and "intend
> to" means the next 10 years or how much the codebase is going to be used.
> That was the reason why I was wondering why do you (you as all people who
> are using this idea) think that end() is calculated and it takes so much
> CPU that it is worth the risk you have just described above.  Especially in
> the light of end() (on many implementations) just returning a member
> variable.

Premature optimisation is the root of all evil!

Lois



More information about the Effective-cpp mailing list