home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!mcsun!sunic!ericom!falcon!jonas
- From: jonas@beppe.ericsson.se (Jonas Nygren)
- Subject: Re: iteration without iterators (and a questio
- Message-ID: <1992Jul23.071535.4208@ericsson.se>
- Sender: news@ericsson.se
- Nntp-Posting-Host: falcon.ericsson.se
- Reply-To: jonas@beppe.ericsson.se
- Organization: Ericsson Telecom AB
- References: <46960006@hpscit.sc.hp.com>
- Date: Thu, 23 Jul 1992 07:15:35 GMT
- Lines: 32
-
- In article 46960006@hpscit.sc.hp.com, weeks@hpscit.sc.hp.com (Greg Weeks) writes:
- >This note is divided into two (brief) independent parts. The first part
- >describes a simple iteration protocol. The second part asks for help in
- >implementing it. (Readers who just want to be helpful can skip to the
- >second part.)
- >
- >THE ITERATION PROTOCOL
- >
- >Let `col' be a collection that holds items of type `Item'. Here is a
- >very simple iteration protocol:
- >
- > for (Item *pi = col.first(); pi; pi = col.next(pi)) {
- > ...
- > // `pi' is the address of an item in the collection.
- > }
- .
- .
- .
- >>This discussion is leaning in the direction of messy
- >implementation-dependent considerations. Is there some nice way to avoid
- >this?
- >
- >Greg Weeks
-
-
- One solution might be to let the class describing col define its own data
- structure, cursor, and then let Item contain one such data member.
- On each call to first and next col will update pi's cursor. This solution
- requires that pi is given as an argument to first in the above example.
-
- /jonas
-
-