iterator beyond the first element

Discussion in 'C++' started by Neelesh Bodas, Nov 28, 2005.

  1. C++ guarantees that there exists a valid iterator beyond the last
    element of a container. However, such iterator might not be written or
    dereferenced. This is also true for arrays - C++ gurantees that there
    exists one position available beyond the end of array.

    Does it give similar guarantee about the position before the first
    element - the position indicated by the iterator rbegin()? (For arrays
    as well as standard containers)
    Neelesh Bodas, Nov 28, 2005
    #1
    1. Advertising

  2. Neelesh Bodas wrote:
    > the position indicated by the iterator rbegin()? (For arrays
    > as well as standard containers)


    Typo. should be rend()
    Neelesh Bodas, Nov 28, 2005
    #2
    1. Advertising

  3. Neelesh Bodas wrote:
    > C++ guarantees that there exists a valid iterator beyond the last
    > element of a container. However, such iterator might not be written or
    > dereferenced. This is also true for arrays - C++ gurantees that there
    > exists one position available beyond the end of array.
    >
    > Does it give similar guarantee about the position before the first
    > element - the position indicated by the iterator rbegin()? (For arrays
    > as well as standard containers)


    You are mistaken about at least one thing: 'rbegin()' returns an iterator
    that points to the _last_ element, not first.

    No, C++ does not guarantee the existence of "one-before-first" iterator
    (in your terms it would be '--begin()').

    V
    Victor Bazarov, Nov 28, 2005
    #3
  4. Neelesh Bodas

    Pete Becker Guest

    Neelesh Bodas wrote:
    >
    > Does it give similar guarantee about the position before the first
    > element


    No.

    > the position indicated by the iterator rbegin()?


    rbegin() is completely different. Reverse iterators for containers use
    the end() and begin() iterators and index one off from the iterator's
    position.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
    Pete Becker, Nov 28, 2005
    #4
  5. Neelesh Bodas

    Sumit Rajan Guest

    "Neelesh Bodas" <> wrote in message
    news:...
    > C++ guarantees that there exists a valid iterator beyond the last
    > element of a container. However, such iterator might not be written or
    > dereferenced. This is also true for arrays - C++ gurantees that there
    > exists one position available beyond the end of array.
    >
    > Does it give similar guarantee about the position before the first
    > element - the position indicated by the iterator rbegin()? (For arrays
    > as well as standard containers)



    If you have a copy of "The C++ Standard Library" close to you, please take a
    look at Section 7.4.1. You will find a detailed explanation on this.


    Regards,
    Sumit.
    --
    Sumit Rajan <>
    Sumit Rajan, Nov 28, 2005
    #5
  6. Pete Becker wrote:
    > rbegin() is completely different. Reverse iterators for containers use
    > the end() and begin() iterators and index one off from the iterator's
    > position.


    Yeah, that was a typo. And yes, I get what you are saying - you mean to
    say that the logical position and physical position of reverse
    iterators are different - they are one unit off - Is that right? If so,
    My confusion is resolved.
    Neelesh Bodas, Nov 28, 2005
    #6
  7. Sumit Rajan wrote:
    > If you have a copy of "The C++ Standard Library" close to you, please take a
    > look at Section 7.4.1. You will find a detailed explanation on this.


    Thanks Sumit, Just opened Josuttis' Book. :)
    Neelesh Bodas, Nov 28, 2005
    #7
    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. Hendrik Maryns
    Replies:
    18
    Views:
    1,404
  2. greg
    Replies:
    6
    Views:
    447
    Dietmar Kuehl
    Jul 17, 2003
  3. Guest
    Replies:
    7
    Views:
    664
    Walter Wang [MSFT]
    Jun 28, 2006
  4. HANM
    Replies:
    2
    Views:
    697
    Joseph Kesselman
    Jan 29, 2008
  5. Szabolcs Borsanyi
    Replies:
    6
    Views:
    652
    Ben Bacarisse
    May 23, 2008
Loading...

Share This Page