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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,70414f56d810c10c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.6.199 with SMTP id d7mr1571822pba.30.1316503746576; Tue, 20 Sep 2011 00:29:06 -0700 (PDT) Path: lh7ni970pbb.0!nntp.google.com!news1.google.com!goblin1!goblin2!goblin.stu.neva.ru!news.internetdienste.de!noris.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 20 Sep 2011 09:29:04 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: discriminant questions References: <9f37b726-d80b-4d24-bf3f-28a14255f7fd@s20g2000yql.googlegroups.com> <708a1202-d480-451b-9b55-00b31ad9c452@w28g2000yqw.googlegroups.com> <1kx7ltnsal62q.195k449mr947t.dlg@40tude.net> In-Reply-To: Message-ID: <4e7840c1$0$7608$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 20 Sep 2011 09:29:05 CEST NNTP-Posting-Host: f2c341a5.newsspool1.arcor-online.net X-Trace: DXC=]]ejVH]Qg\^U`I`eMB16]GJ;8E;F X-Complaints-To: usenet-abuse@arcor.de Xref: news1.google.com comp.lang.ada:18038 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2011-09-20T09:29:05+02:00 List-Id: On 19.09.11 19:49, ytomino wrote: > -- "count" algorithm with Ada 2005 version > generic > type Element_Type (<>) is private; > type Cursor is private; > type Container is private; > package Iterator_Interfaces is > new Ada.Iterator_Interfaces (Cursor, others => <>); > with function Iterate (C : Container) > return Iterator_Interfaces.Forward_Iterator'Class; > type Constant_Reference_Type ( > Element : not null access constant Element_Type) with private; > <- *B* > with function Constant_Reference (C : Container; P : Cursor) > return Constant_Reference_Type; > procedure Generic_Count (C : Container; Value : Element_Type) return > Count_Type; > > There is no way to use a instance of Vectors.Constant_Reference_Type > as *B*. (I have taken the liberty of choosing name `Iterator` for formal function `Iterate`, since a different `Iterate` is already taken by the container packages.) function Generic_Count (C : Container; Value : Element_Type) return Ada.Containers.Count_Type is use type Ada.Containers.Count_Type; Sum : Ada.Containers.Count_Type := 0; -- overall result procedure Use_CRefT (Wrap : Constant_Reference_Type) is begin if Wrap.Element.all = Value then Sum := Sum + 1; end if; end Use_CRefT; procedure Search (Position : Cursor) is Element_To_Be_Pointed_At : Constant_Reference_Type renames Constant_Reference (C, Position); begin Use_CRefT(Element_To_Be_Pointed_At); end Search; Star : Iterator_Interfaces.Forward_Iterator'Class := Iterator (C); Pos : Cursor; begin Pos := Iterator_Interfaces.First (Star); while Pos /= Iterator_Interfaces.No_Element loop Search (Pos); Pos := Iterator_Interfaces.Next (Star, Pos); end loop; return Sum; end Generic_Count; I think, though, that Query_Element will obviate the need for the wrapping pointer types; not sure I understand why you want them. Is this influenced by a 1:1 transport of C++ STL algorithms? I wonder whether the C++ STL would be different if C++ could use proper nesting or in case it had drawn more attention to function objects.