From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:a37:bfc5:0:b0:6cd:d800:ab55 with SMTP id p188-20020a37bfc5000000b006cdd800ab55mr4458906qkf.176.1663342926910; Fri, 16 Sep 2022 08:42:06 -0700 (PDT) X-Received: by 2002:ae9:c30b:0:b0:6cd:f128:cc88 with SMTP id n11-20020ae9c30b000000b006cdf128cc88mr4503547qkg.0.1663342926741; Fri, 16 Sep 2022 08:42:06 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 16 Sep 2022 08:42:06 -0700 (PDT) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=46.15.217.19; posting-account=uulyKwoAAAA86DO0ODu--rZtbje8Sytn NNTP-Posting-Host: 46.15.217.19 References: <6a8a1468-5148-49d7-b342-327f8eaf8097n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <7c1a505d-9214-40ba-93b7-84afad1e10a3n@googlegroups.com> Subject: Re: Non-standard functions in GNAT's Ada.Containers packages? From: Egil H H Injection-Date: Fri, 16 Sep 2022 15:42:06 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 3163 Xref: reader01.eternal-september.org comp.lang.ada:64341 List-Id: On Friday, September 16, 2022 at 5:00:29 PM UTC+2, amado...@gmail.com wrote: > > >> "for X of M loop ... end loop". > > > > > > Not possible for maps. > > but you can as > > >https://programming-idioms.org/idiom/13/iterate-over-map-keys-and-value/1511/ada> > > > > with Ada.Containers.Indefinite_Hashed_Maps; > > with Ada.Strings.Hash; > > use Ada.Containers; > > for C in My_Map.Iterate loop > > Put_Line ("Key = " & Key (C) & ", Value = " & Element (C)); > > end loop; > Thanks, but this is "in", not "of", requires cursors, and DOES NOT COMPILE, as probably needs like ten lines of boiler plate not show. (sorry for any botched formatting...) with Ada.Containers.Indefinite_Hashed_Maps; with Ada.Strings.Hash; with Ada.Text_IO; procedure Iteration is package My_Maps is new Ada.Containers.Indefinite_Hashed_Maps (String, Integer, Ada.Strings.Hash, "="); My_Map : My_Maps.Map; begin My_Map.Include("One", 1); My_Map.Include("Two", 2); My_Map.Include("Three", 3); for C in My_Map.Iterate loop Ada.Text_IO.Put_Line(My_Maps.Key(C) & My_Maps.Element(C)'Image); end loop; for Element of My_Map loop Ada.Text_IO.Put_Line(Element'Image); end loop; -- Ada_2022: -- for (C : My_Maps.Cursor) of My_Map.Iterate loop -- Ada.Text_IO.Put_Line(My_Maps.Key(C) & My_Maps.Element(C)'Image); -- end loop Ada_2022; end Iteration; I don't know why they left out a two-parameter version of the Iterate procedure for Ada 2022 Maps, -- for (Key, Element) of My_Map.Iterate loop would've been nice, just like -- for (Name, Val) of Ada.Environment_Variables.Iterate(<>) loop