Topic: vector invalidating iterator.
Author: Srinivas Nayak <sinu.nayak2001@gmail.com>
Date: Wed, 15 Sep 2010 14:10:46 CST Raw View
Hi,
When we use vector::erase(iterator); after erasing an element from
vector, it invalidates the iterator. Where as this method "returns" a
correct iterator to the next element. Is there any particular
reason(implementation specific) why vector::erase(iterator); doesn't
modify the iterator(to correct one as it returns) passed as argument?
Sincerely,
Srinivas Nayak
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Wed, 15 Sep 2010 17:27:04 CST Raw View
On 15 Sep., 22:10, Srinivas Nayak <sinu.nayak2...@gmail.com> wrote:
> When we use vector::erase(iterator); after erasing an element from
> vector, it invalidates the iterator. Where as this method "returns" a
> correct iterator to the next element. Is there any particular
> reason(implementation specific) why vector::erase(iterator); doesn't
> modify the iterator(to correct one as it returns) passed as argument?
You couldn't provide an rvalue as argument to this function.
Also, I expect that most users would find it quite astonishing,
if there argument would have been changed here: What is wrong
with the return value? It has also another disadvantage: The
function accepts (now) a const_iterator and returns an iterator.
This means that the function would be less use-ful as
currently.
HTH & Greetings from Bremen,
Daniel Kr=FCgler
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]