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

Balog Pal pasa at lib.hu
Tue Oct 26 09:18:12 EDT 2004


> I wonder if the use of v[n] is a candidate for premature optimisation

It has nothing to do with optimisation.
v[n] is the thing to call when you know that element exist. It will give you
the element and that's it.

at() is to be alled when you don't know the element is there, and wnt to
handle the not exist case on some catch() branch upper there.   [I'd guess
it is a rare and very special occasion.]

Using at() instead of [] just on whim, or for 'it feels safer with that
check' is recipe for disaster.





More information about the Effective-cpp mailing list