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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bae7ef2665942955 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-13 10:10:46 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread1.news.atl.earthlink.net.POSTED!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: containers and garbage collections. References: <2458809.CYNMQ0Kujp@linux1.krischik.com> <23635057.dHrhOAZpeb@linux1.krischik.com> From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 13 Sep 2003 17:10:45 GMT NNTP-Posting-Host: 65.110.133.134 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.atl.earthlink.net 1063473045 65.110.133.134 (Sat, 13 Sep 2003 10:10:45 PDT) NNTP-Posting-Date: Sat, 13 Sep 2003 10:10:45 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:42449 Date: 2003-09-13T17:10:45+00:00 List-Id: Martin Krischik writes: > Matthew Heaney wrote: > > > Both of these containers are possible using the single declaration: > > > > generic > > type Element_Type (<>) is private; > > package GP is ...; > > > > You can instantiate GP using either of the types in your example. It's > > not clear why you made two separate containers, one for tagged types > > vs. another for array types, as a single container seems adequate. > > Will it work with any combination of tagged types incl. controled types any > derived types of Element_Type? If so I stay corrected and will rething my > design. Yes, it will work for any combination of tagged type. All you need to do is specify T'Class as the generic actual: package P is new GP (T'Class); This works becuase of Ada's built-in cloning facility. So when you say X : Element_Access := new Element_Type'(Item); this means X : T_Class_Access := new T'Class'(Item); and now X designates a copy of Item, having the same type tag as Item. When you query the item, just do this: E : T'Class := Top (Q); This makes a copy of the (indefinite) element at the front of the queue. If you want to be able to dispatch on the tag of an item in the container, without having to make a copy of item, then you can expose the internal pointer: E : constant Element_Access := Top_Access (Q); begin Op (E.all); --dispatch