iterator beyond the first element

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neelesh Bodas

    #1

    iterator beyond the first element

    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

    #2
    Re: iterator beyond the first element


    Neelesh Bodas wrote:[color=blue]
    > the position indicated by the iterator rbegin()? (For arrays
    > as well as standard containers)[/color]

    Typo. should be rend()

    Comment

    • Pete Becker

      #3
      Re: iterator beyond the first element

      Neelesh Bodas wrote:[color=blue]
      >
      > Does it give similar guarantee about the position before the first
      > element[/color]

      No.
      [color=blue]
      > the position indicated by the iterator rbegin()?[/color]

      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)

      Comment

      • Sumit Rajan

        #4
        Re: iterator beyond the first element


        "Neelesh Bodas" <neelesh.bodas@ gmail.com> wrote in message
        news:1133188428 .317619.131460@ f14g2000cwb.goo glegroups.com.. .[color=blue]
        > 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)[/color]


        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 <sumitr@msdc.hc ltech.com>


        Comment

        • Neelesh Bodas

          #5
          Re: iterator beyond the first element


          Pete Becker wrote:[color=blue]
          > rbegin() is completely different. Reverse iterators for containers use
          > the end() and begin() iterators and index one off from the iterator's
          > position.[/color]

          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.

          Comment

          • Victor Bazarov

            #6
            Re: iterator beyond the first element

            Neelesh Bodas wrote:[color=blue]
            > 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)[/color]

            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

            Comment

            • Neelesh Bodas

              #7
              Re: iterator beyond the first element

              Sumit Rajan wrote:[color=blue]
              > 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.[/color]

              Thanks Sumit, Just opened Josuttis' Book. :-)

              Comment

              Working...