home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11401 < prev    next >
Encoding:
Text File  |  1992-07-22  |  1.4 KB  |  46 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!mcsun!sunic!ericom!falcon!jonas
  3. From: jonas@beppe.ericsson.se (Jonas Nygren)
  4. Subject: Re: iteration without iterators (and a questio
  5. Message-ID: <1992Jul23.071535.4208@ericsson.se>
  6. Sender: news@ericsson.se
  7. Nntp-Posting-Host: falcon.ericsson.se
  8. Reply-To: jonas@beppe.ericsson.se
  9. Organization: Ericsson Telecom AB
  10. References: <46960006@hpscit.sc.hp.com>
  11. Date: Thu, 23 Jul 1992 07:15:35 GMT
  12. Lines: 32
  13.  
  14. In article 46960006@hpscit.sc.hp.com, weeks@hpscit.sc.hp.com (Greg Weeks) writes:
  15. >This note is divided into two (brief) independent parts.  The first part
  16. >describes a simple iteration protocol.  The second part asks for help in
  17. >implementing it.  (Readers who just want to be helpful can skip to the
  18. >second part.)
  19. >
  20. >THE ITERATION PROTOCOL
  21. >
  22. >Let `col' be a collection that holds items of type `Item'.  Here is a
  23. >very simple iteration protocol:
  24. >
  25. >    for (Item *pi = col.first(); pi; pi = col.next(pi)) {
  26. >    ...
  27. >    //  `pi' is the address of an item in the collection.
  28. >    }
  29. .
  30. .
  31. .
  32. >>This discussion is leaning in the direction of messy
  33. >implementation-dependent considerations.  Is there some nice way to avoid
  34. >this?
  35. >
  36. >Greg Weeks
  37.  
  38.  
  39. One solution might be to let the class describing col define its own data
  40. structure, cursor, and then let Item contain one such data member. 
  41. On each call to first and next col will update pi's cursor. This solution
  42. requires that pi is given as an argument to first in the above example.
  43.  
  44. /jonas
  45.  
  46.