Re: Should an iterator be valid after appending to a Glib::ustring?



On 14/03/17 10:39 AM, Daniel Boles wrote:
On 14 March 2017 at 14:29, Krzysztof Piecuch via gtkmm-list < 
gtkmm-list gnome org> wrote:

What about ustring.end() iterator? I think it's obvious that it's 
invalidated each time we change the string's length (unless it's 
done in some *very clever* way). It's a thing no reserve()-ation 
can help.


Right, yeah. Whether an iterator can remain valid also depends on 
what it represents, and .end() is especially vulnerable. Good point!

The simple rule: mutating the container cause iterators to be
invalidated, unless if explicitly said otherwise, like std::list<>.

http://en.cppreference.com/w/cpp/container/list

Addition, removal and moving the elements within the list or across 
several lists does not invalidate the iterators or references. An 
iterator is invalidated only when the corresponding element is 
deleted.


Hub



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]