Thread: Iterators

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    11

    Question Iterators

    Can anyone explain what an iterator is??

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    There are also input stream iterators that make filling/displaying containers much easier.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    the word iterator is almost synonymous with the word placeholder. That is, an iterator is used to store a position of an element. (either in a container or a stream)

    You may be familiar with the way that a pointer can be used as a 'placeholder' for an element in an array; an iterator is really just a neatly packaged abstraction of that concept. (with built in range checking, so its safer too)

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> with built in range checking, so its safer too
    The concept of an iterator does not include range checking, and most STL iterators also do not include built-in range checking.

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by Daved
    >> with built in range checking, so its safer too
    The concept of an iterator does not include range checking, and most STL iterators also do not include built-in range checking.
    ah ok, my bad. I was under the impression that STL iterators would throw an out of range exception if you went beyond the container limits. then again, perhaps that's not really range checking

  7. #7
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    I think the .at() function with strings does that, out of range checking I mean. Not sure about whether vectors have that ...

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Vectors have at(), and it throws.

    No iterator I've ever seen throws. They might assert(), but they do not throw.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    11

    Smile thanks

    thanks for the help. I got it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector of strings with iterators.
    By Mario F. in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2006, 12:12 PM
  2. Using reverse iterators in algorithms
    By 0rion in forum C++ Programming
    Replies: 1
    Last Post: 02-27-2006, 03:19 AM
  3. Writing Iterators...
    By Geolingo in forum C++ Programming
    Replies: 6
    Last Post: 05-29-2003, 09:31 PM
  4. accessing vector elements: iterators are faster?
    By Captain Penguin in forum C++ Programming
    Replies: 1
    Last Post: 11-28-2002, 02:27 PM
  5. Generic Progpammimg Iterators
    By rip1968 in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2002, 10:20 AM