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,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-23 19:13:15 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: Is the Writing on the Wall for Ada? References: <568ede3c.0309160929.1d0d3d95@posting.google.com> <3F67AFB9.7040001@attbi.com> <3F6F0841.60607@attbi.com> <1064244399.683441@master.nyc.kbcfp.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: Wed, 24 Sep 2003 02:13:15 GMT NNTP-Posting-Host: 65.110.133.134 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.atl.earthlink.net 1064369595 65.110.133.134 (Tue, 23 Sep 2003 19:13:15 PDT) NNTP-Posting-Date: Tue, 23 Sep 2003 19:13:15 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:42836 Date: 2003-09-24T02:13:15+00:00 List-Id: Dmitry A. Kazakov writes: > (**) BTW a great unsolvable problem in both Ada and C++, both with MI > or without, is to make a container of a subtype a subtype of the > container of the base type. Which highlights present problems with ADT > and *helpless* attempts to solve this using templates. Au contraire. The *simplest* way to solve that problem is using templates. package P is type T is tagged null record; procedure Op (O : in out T); end P; package P.C is type NT is new T with null record; procedure Op (O : in out T); end; function "<" (L, R : P.T) return Boolean is ...; package T_Sets is new Ada.Containers.Sets.Sorted.Unbounded (P.T); function "<" (L, R : P.C.NT) return Boolean is ...; package NT_Sets is new Ada.Containers.Sets.Sorted.Unbounded (P.C.NT); T_Set : T_Sets.Container_Type; NT_Set : NT_Sets.Container_Type; Now let's say you want an algorithm that can operate over the items in either of the set containers declared above. After all, that why you wanted NT_Set to be a subtype of T_Set. So let's just abstract-away the container: generic type Iterator_Type is private; with procedure Succ (Iter : Iterator_Type) return Iterator_Type is <>; function To_T (Iter : Iterator_Type) return T_Class_Access; procedure Generic_Algorithm (First, Back : Iterator_Type); Now I can do this: function To_T is new T_Sets.Generic_Element (T_Class_Access); --check this function To_T is new NT_Sets.Generic_Element (T_Class_Access); --ditto And now I do this: procedure Algorithm is new Generic_Algorithm (T_Sets.Iterator_Type); procedure Algorithm is new Generic_Algorithm (NT_Sets.Iterator_Type); And so now I can do this: Algorithm (First (T_Set), Back (T_Set)); Algorithm (First (NT_Set), Back (NT_Set)); Problem solved. No MI or base types or inheritance or interfaces or any other crap is needed. Generics work just fine thank you very much.