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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.151.78 with SMTP id z75mr45568824iod.31.1448664726358; Fri, 27 Nov 2015 14:52:06 -0800 (PST) X-Received: by 10.182.166.8 with SMTP id zc8mr274938obb.18.1448664726340; Fri, 27 Nov 2015 14:52:06 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!mv3no4392962igc.0!news-out.google.com!l1ni184igd.0!nntp.google.com!mv3no5659112igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 27 Nov 2015 14:52:05 -0800 (PST) In-Reply-To: <3a6f986a-f5f3-4175-b191-b0133e70ff66@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=68.145.219.148; posting-account=GO34ygoAAABjKWQJiUlszgvYtyWwgCPW NNTP-Posting-Host: 68.145.219.148 References: <0c524381-442a-49cc-9d72-27a654320153@googlegroups.com> <2n6rk7i078ph.cs60h3ciaojr.dlg@40tude.net> <3a6f986a-f5f3-4175-b191-b0133e70ff66@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Two approaches of iterators for the key-value pairs From: bj.mooremr@gmail.com Injection-Date: Fri, 27 Nov 2015 22:52:06 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:28575 Date: 2015-11-27T14:52:05-08:00 List-Id: On Friday, November 27, 2015 at 11:08:25 AM UTC-7, ytomino wrote: > On Saturday, November 28, 2015 at 1:30:23 AM UTC+9, Dmitry A. Kazakov wrote: > > Rather this: > > > > for Variable in All_Variables loop > > Put_Line (Variable.Name & "=" & Variable.Value); > > end loop; > > It sounds good. > > However, the Cursor probably have to be tagged to implement it for dot-notation, and, I think it will be an double-dispatching error on First/Next because the iterator is also tagged. > > I wish dot-notation for non-tagged type is allowed (with pragma?) My initial implementation of this was as an Iterator, rather than an Iterable container, and in my implementation, I got things to work this way without the Cursor being a tagged type. My "proof of concept" implementation was for Ada.Directories, but the same approach would also work for Ada.Environment_Variables. For Ada.Directories, I declared the Cursor type as; type Cursor (Directory_Entry : not null access constant Directory_Entry_Type) is private with Implicit_Dereference => Directory_Entry; The Implicit_Dereference aspect was added to Ada 2012. For Ada.Environment_Variables, I would have declared something like; type Cursor (Name_Value_Pair : not null access constant Name_Value_Pair_Type) is private with Implicit_Dereference => Name_Value_Pair; And function Has_Element (Name_Value_Pair : Cursor) return Boolean; package Environment_Variable_Iterator_Interfaces is new Ada.Iterator_Interfaces (Cursor => Cursor, Has_Element => Has_Element); function All_Variables return Environment_Variable_Iterator_Interfaces.Forward_Iterator'Class; Then one would be able to write; for Variable in All_Variables loop Put_Line (Variable.Name & "=" & Variable.Value); end loop; Exactly as Dmitry had requested... Brad