From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1042f393323e22da X-Google-Attributes: gid103376,public From: Jeff Carter Subject: Iterator Syntax [was: Re: STL in Ada95] Date: 1997/05/23 Message-ID: <33859890.5587@spam.innocon.com>#1/1 X-Deja-AN: 243318665 References: <337813DF.598C@dynamite.com.au> <337D3AE4.28F7@dynamite.com.au> <337E5854.1366@sprintmail.com> <12871CEBFAB00ABE.93483F73373D0261.D1086334F6EF8ED8@library-proxy.airnews.net> <3380F4A5.1EBB@sprintmail.com> <33838C37.29C0@sprintmail.com> Organization: Wouldn't You Like to Know, Inc. Reply-To: carter@spam.innocon.com Newsgroups: comp.lang.ada Date: 1997-05-23T00:00:00+00:00 List-Id: Brian Rogoff wrote: > > John Volan wrote: ... > > generic > > type Iterator_Type is private; > > type Item_Type is private; > > with procedure Advance (Iterator : in out Iterator_Type); > > with function Get_Item (Iterator : in Iterator_Type) return > > Item_Type; > > ... -- whatever other formals > > procedure Do_Whatever -- whatever the algorithm is > > (Start, Stop : in Iterator_Type; ... ); -- whatever parameters I'm curious. What is the advantage of "exposed" iterators like these over encapsulated iterators for a structure: generic -- Iterate with procedure Action (Item : in out Element; Continue : out Boolean); procedure Iterate (Over : in Structure); The most typical usage, in my experience, has been to process every Element in the Structure. Stopping before the end is rare; skipping some at the beginning is even rarer. Processing every Element is easy for the client with an encapsulated iterator (even easier if you leave the Continue parameter out of Action). The exposed iterator requires the client to set up Start and Stop and provide appropriate Advance and Get_Item operations. -- Jeff Carter PGP:1024/440FBE21 Auntie-spam reply-to; try ( carter @ innocon . com ) "Now go away, or I shall taunt you a second time." Monty Python & the Holy Grail