su**************@yahoo.com, India wrote:
For vector and deque, the 'at( )' member function throws out_of_range
exception if the argument to the 'at( )' function is not in range. But
the subscript operator [ ] does not throw this exception for the same
situation.
My question:
Why can't the subscript operator [ ] itself throw the out_of_range
exception in which case the 'at ( )' member function may not be
needed ?
Because that's usually not what you want. You want some sort of
implementation defined crash, the equivalent of an assertion
failure. Undefined behavior allows the implementation to
provide this (and also allows removing the checks, if you find
that they create too much runtime overhead).
--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34