Re: Validity of references returned from iterators

Discussion in 'C++' started by Öö Tiib, Jul 31, 2013.

  1. Öö Tiib

    Öö Tiib Guest

    On Wednesday, 31 July 2013 08:07:09 UTC+3, Christopher Head wrote:
    > I was in the process of writing an STL-style iterator class. I grabbed
    > N3337 (as I don’t have access to the actual standard) and looked at the
    > requirements for the various iterator types. I couldn’t seem to find,
    > anywhere, the rules describing over what period of time pointers and
    > references returned from iterators are valid.


    On general case all the references, pointers and iterators are valid as
    long the container has not been modified.

    If the container has been modified then what happens to iterators is often
    described about each container and each operation separately. It is because
    the details may be quite complex even for simplest of containers. For
    example when you push_back() element to std::vector AND reallocation
    happens then all iterators, pointers and references become invalid. However
    if reallocation does not happen (there was enough storage in reserve)
    then only end() iterator becomes invalid.
    Öö Tiib, Jul 31, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. falcon
    Replies:
    4
    Views:
    511
  2. Marcin Kaliciñski

    Iterators and reverse iterators

    Marcin Kaliciñski, May 8, 2005, in forum: C++
    Replies:
    1
    Views:
    478
    Kai-Uwe Bux
    May 8, 2005
  3. , India
    Replies:
    10
    Views:
    1,060
    James Kanze
    Aug 8, 2009
  4. James Kanze
    Replies:
    0
    Views:
    176
    James Kanze
    Jul 31, 2013
  5. Christopher Head
    Replies:
    0
    Views:
    146
    Christopher Head
    Aug 11, 2013
Loading...

Share This Page