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-Thread: 103376,243dc2fb696a49cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!wn14feed!worldnet.att.net!208.48.142.85!newsfeed.news2me.com!newsfeeds.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada References: <41547dae$0$91007$39cecf19@news.twtelecom.net> Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) Date: Mon, 27 Sep 2004 12:21:15 -0400 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Message-ID: <41583b4c$0$74190$39cecf19@news.twtelecom.net> Organization: Time-Warner Telecom NNTP-Posting-Date: 27 Sep 2004 16:09:48 GMT NNTP-Posting-Host: 49fefccb.news.twtelecom.net X-Trace: DXC=O^fW`YS00F0XPjNm[V63b>C_A=>8kQj6=MOj3YM9`=a8>Nf`US;7g=:dYZAA8S:UJhM_]lN0 X-Complaints-To: abuse@twtelecom.net Xref: g2news1.google.com comp.lang.ada:4277 Date: 2004-09-27T16:09:48+00:00 List-Id: "Kevin Cline" wrote in message news:e749549b.0409270631.2bf81ccf@posting.google.com... > Matthew Heaney wrote in message news:... > > kevin.cline@gmail.com (Kevin Cline) writes: > > > > Indeed, you cannot do this. In AI-302 (and in Ada.Strings.*), you have to say: > > > > Replace_Element (C, Index => 5, By => 7); > > I think this was a major error in the language design. As a result it > very tedious to write a generic that will work with both predefined > and user-defined types. All you need to do is write the generic in terms of (AI-302) container operations, and then use locally declared subprograms to make the array (say) work with the generic algorithm. The "tedium" only applies when using a generic on an array instead of a container. For example: generic type Cursor is private; with function Next (C : Cursor) return Cursor is <>; with procedure Replace_Element (C : Cursor; By : ET) is <>; with function Has_Element (C : Cursor) return Boolean is <>; procedure Generic_Op (C : Cursor); To use this with a container type, there's nothing you need to do except instantiate the generic algorithm. To make this work with an array, all you need to do is: procedure Op (A : in out Array_Type) is procedure Replace_Element (I : Index_Type; E : ET) is begin A (I) := E; end; function Has_Element (I : IT) return Boolean is begin return I in A'Range; end; procedure Algorithm is new Generic_Algorithm (Index_Type, Index_Type'Succ); begin Algorithm (A'First); end Op; Note that here the "cursor" is just the discrete array index subtype. The T'Succ attribute is used as the generic actual for the Next generic formal. Your problem is that you're still thinking in C++ terms. C++ works by making containers look like built-in types. That's different from Ada, which (as demonstrated above) makes the built-in type look like a container. -Matt