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,3d6e3f68a9ab5a3c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-13 11:31:00 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: Charles: Generic_Find Date: 13 Nov 2002 11:31:00 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0211131130.3dfb22b9@posting.google.com> References: <3dd082fe$0$307$bed64819@news.gradwell.net> <1037108893.573381@master.nyc.kbcfp.com> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1037215860 8142 127.0.0.1 (13 Nov 2002 19:31:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 13 Nov 2002 19:31:00 GMT Xref: archiver1.google.com comp.lang.ada:30829 Date: 2002-11-13T19:31:00+00:00 List-Id: "Frank J. Lhota" wrote in message news:... > "Hyman Rosen" wrote in message > news:1037108893.573381@master.nyc.kbcfp.com... > > It also introduces potentially significant optimization > > opportunities, since for predicates, function call overhead can > > easily dwarf the amount of computation done by the predicate > > itself. > > In other words, the possibility of inlining the function is possible with > the template / generic approach,whereas the pointer-to-function approach > would force a function call. Yes, but not just that. In Ada downward chains must be static. Consider my previous employee example, and assume we want to count how many employees are male: Employees : Container_Subtype; function Count (Sex : Sex_Type) return Natural is function Predicate (E : Employee_Type) return Boolean is begin return E.Sex = Sex; end; function Find is new Generic_Find (Predicate); Result : Natural := 0; Back : constant Iterator_Type := Employees_Types.Back (Employees); Iter : Iterator_Type = First (Employees); begin loop Iter := Find (Iter, Back); if Iter = Back then return Result; end if; Result := Result + 1; Iter := Succ (Iter); end loop; end Count; This implementation (a locally declared subprogram that uses the parameters of the enclosing subprogram) is very natural in Ada, but doesn't have a direct translation in C++.