Generic Progpammimg Iterators

This is a discussion on Generic Progpammimg Iterators within the C++ Programming forums, part of the General Programming Boards category; I am studying from C++ Primer Plus third edition and have reached the point that os trying to explain iterators ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    95

    Generic Progpammimg Iterators

    I am studying from C++ Primer Plus third edition and have reached the point that os trying to explain iterators and Generic Programming. This seems like the hardest point in the book and I was hoping for some input from the board. ie code examples further tutorials whatever you can post to help me understand iterators and generic programming would be much appreciated!

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    In my data structures and algo class we had to do this, make some iterators for a class we designed earlier in the year.
    It was probably the hardest lab that we had to do, but that was becuase the handout we got was pretty vague, and was more like fill in the code blanks.
    Im sorry to say i dont have that code anymore
    If i find anythink ill post it here

  3. #3
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    As far as I know the STL uses interators to acesses generic containers because the implementation of the containers are different. For example, vectors are useful for random access and Lists are useful for deleting/adding members within the container. Each STL container has strength and weaknesses and the iterator is different for each container. I believe that the iterators are part of an inheritance hierarchy, not 100% sure of that though.

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    The following only pertains to the STL

    STL iterators are not part of a hierarchy. While their implementation is all different, they can be classified into five distinct categories,

    random access, most powerful, can access arbitrary points (100 ahead, 50 back) in constant time. Can be written to and read from. vector iterators are random access.

    bidirectional. Can iterate one element at a time, forward or backward. A random access iterator has a superset of the abilities of a bidirectional iterator. list iterators are bidirectional.

    single directional (forward?). Can iterate only forward through a forward iterator. Can read and write to it. slist (non-standard) singly linked list class iterators are forward iterators.

    output iterator. Can only be written to. Used in output streams.

    input iterator. Can only be read from, used in input streams.

    They could be made into an inheritance hierarcy, but they are not. If you want to exploit their genericity, you need to use templates.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    My book is in my truck, but it mentioned that something was part of a hierarchy. I'll look it up sometime.

  6. #6
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    C++ uses internal iterators, the iterator object controls the iteration rather than the client.

    I have the whole design pattern literature, and my C++ book that said something about it, but I didn't find it yet.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    95
    I appreciate your posts.
    I am still interested in how to implement iterators for container classes (user defined) and code examples using the Hierarchy mentioned above especially the lower level iterators(input, output etc.)

    C++ primer plus just brushes over this area showing mostly how to use iterators not how to create them.

  8. #8
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    I have not looked at my book yet, however if you want a real reference with examples than get the Gang Of Four book called, Design Patterns. According to the Gang Of Four (PHD Doctors of CS), they list iterator as a behavioral pattern. To tell you the truth, at this time, it is over my head, but there are 14 pages just on the iterator pattern alone.

    ISBN: 0201633612

    BTW this book is the bible of design patterns.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. generic printing preferences dialog box
    By stanlvw in forum Windows Programming
    Replies: 8
    Last Post: 06-27-2008, 02:20 AM
  2. vector of strings with iterators.
    By Mario F. in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2006, 12:12 PM
  3. Using reverse iterators in algorithms
    By 0rion in forum C++ Programming
    Replies: 1
    Last Post: 02-27-2006, 02:19 AM
  4. Generic Host Proccess Shutdown
    By Tommaso in forum Tech Board
    Replies: 8
    Last Post: 08-14-2003, 11:18 AM
  5. Writing Iterators...
    By DeepBlackMagic in forum C++ Programming
    Replies: 6
    Last Post: 05-29-2003, 09:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21