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

David Sykes davidsykes234 at yahoo.com
Tue Oct 26 07:41:30 EDT 2004


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

"Timothy C. Wright" <tim at tcw321.com> wrote:
There are two accessors for the vector container that have slighty 
different meaning. v[0] gets the zeroeth element of the vector. If 
there is not any elements in the vector, then we don't know what will 
happen. The standard allows bounds checking but does not require it for 
this function. Bounds checking is not required so it can be efficient 
and replace the old array. The other element accessor, v.at(0), does 
require bounds checking and is guaranteed to throw a std::out_of_range 
exception. Understand when you want to use at() verses [].



		
---------------------------------
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.

--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---



More information about the Effective-cpp mailing list