What is faster, const_iterator or iterator?

Discussion in 'C++' started by ul, Aug 25, 2006.

  1. ul

    ul Guest

    Hello,

    Just wonder what is faster for std::vector, const_iterator od iterator?
    Or is this stl-realisation-dependent?
    Target compilator gcc platform is Linux.

    Thanks
    ul, Aug 25, 2006
    #1
    1. Advertising

  2. ul

    Kai-Uwe Bux Guest

    ul wrote:

    > Hello,
    >
    > Just wonder what is faster for std::vector, const_iterator od iterator?
    > Or is this stl-realisation-dependent?


    Formally:

    a) it depends on the STL implementation.
    b) both are random access iterators and have the same performance
    guarantees. But that does not say that constant time operations take the
    same time for both.

    That said, a typical implementation for iterators into a std::vector should
    not be more than a little wrapper around a single pointer and iterator
    movements will be just translated into pointer arithmetic. Thus, both
    versions should be equally fast. However, using the const_iterator may help
    the compiler to do some optimizations in functions that are passed the
    reference object of the iterator.


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Aug 25, 2006
    #2
    1. Advertising

  3. ul

    peter koch Guest

    ul wrote:
    > Hello,
    >
    > Just wonder what is faster for std::vector, const_iterator od iterator?
    > Or is this stl-realisation-dependent?
    > Target compilator gcc platform is Linux.
    >
    > Thanks


    This is implementation defined, but i would be extremely surprised if
    there would be any difference between the two. IF there is a
    difference, it will be a constant factor.

    /Peter
    peter koch, Aug 25, 2006
    #3
    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. CoolPint
    Replies:
    3
    Views:
    730
    CoolPint
    Dec 13, 2003
  2. Replies:
    2
    Views:
    363
    Ferdi Smit
    Oct 23, 2005
  3. John Harrison

    iterator and const_iterator

    John Harrison, Nov 20, 2005, in forum: C++
    Replies:
    5
    Views:
    1,258
    Cy Edmunds
    Nov 20, 2005
  4. Mark P
    Replies:
    2
    Views:
    703
    Bart van Ingen Schenau
    Jun 15, 2006
  5. flopbucket
    Replies:
    1
    Views:
    694
    flopbucket
    Jun 21, 2006
Loading...

Share This Page