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,5d0ce0dbca0a2038 X-Google-Attributes: gid103376,public From: Mats Weber Subject: Re: Q: Primitive operation of a type Date: 1997/07/08 Message-ID: <33C24D61.86746FC7@elca-matrix.ch>#1/1 X-Deja-AN: 255509330 References: <5oq51h$t7u@netline.jpl.nasa.gov> <33BA43CC.E27C69CC@elca-matrix.ch> X-Priority: 3 (Normal) Organization: ELCA Matrix SA Reply-To: Mats.Weber@elca-matrix.ch Newsgroups: comp.lang.ada Date: 1997-07-08T00:00:00+00:00 List-Id: Matthew Heaney wrote: > package Sets_G is > > type Root_Set is abstract tagged private; > > type Root_Set_Iterator is abstract tagged private; > > function New_Iterator (Set : access Root_Set) > return Root_Set_Iterator'Class; > > function Is_Done (Iterator : Root_Set_Iterator) return Boolean; > > procedure Advance (Iterator : in out Root_Set_Iterator); > > function Is_Equal (L : Root_Set'Class; R : Root_Set) return > Boolean; > > procedure Copy (From : Root_Set'Class; To : in out Root_Set); > > ... How about an iterator that is just a procedure ? That way, the iterator is part of the primitive profile of the type and gets inherited (and I'll have to convert all my Ada 83 iterator specifications based on generics :-(). Moreover, it's not always easy to implement an iterator that is a separate type, e.g. if the structure is implemented as an AVL tree, you have to remember the path from the root of the tree to the current node, which makes your iterator less efficent. generic type element_type is private; package sets is type set is abstract tagged private; type action_procedure is access procedure (element : in element_type); procedure enumerate (the_set : in set; action : in action_procedure); ... end sets;