On Fri, 9 May 2014 15:37:15 +0200, Nicky D. wrote:

> > > I notice "operator[](i)" is used in the interesting,
> >
> > With std::vector, you could also use array.at(i), which is equivalent.
>
> vector::at will do a runtime check if the index is out of bounds, in
> that case it throws an exception.
> 
> vector::operator[] will not do this check, causing undefined behavior
> when accessing elements out of bounds.

True, but on the other hand, you'd never call array[i] with i out of
array bound (it would be a bug, and throwing an exception via the use
of at(i) is no better than "undefined behaviour" that will also lead
to a crash in the end). The fact that array[i] doesn't check the upper
bound also makes it faster than array.at(i): competent programmers who
do check for bounds where actually needed will therefore prefer
array[i] to array.at(i), esspecially when used in a loop !

Henri.
_______________________________________________
Policies and (un)subscribe information available here:
http://wiki.secondlife.com/wiki/OpenSource-Dev
Please read the policies before posting to keep unmoderated posting privileges

Reply via email to