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:a05:622a:1651:b0:344:5d06:7449 with SMTP id y17-20020a05622a165100b003445d067449mr5360155qtj.292.1663348103848; Fri, 16 Sep 2022 10:08:23 -0700 (PDT) X-Received: by 2002:a05:620a:1987:b0:6ce:54bf:3fe3 with SMTP id bm7-20020a05620a198700b006ce54bf3fe3mr4813842qkb.394.1663348103154; Fri, 16 Sep 2022 10:08:23 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.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 10:08:22 -0700 (PDT) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=96.241.104.184; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 96.241.104.184 References: <6a8a1468-5148-49d7-b342-327f8eaf8097n@googlegroups.com> <23ae89d7-3f28-4f14-80bc-af794762c756n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Non-standard functions in GNAT's Ada.Containers packages? From: Jere Injection-Date: Fri, 16 Sep 2022 17:08:23 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 3363 Xref: reader01.eternal-september.org comp.lang.ada:64348 List-Id: On Friday, September 16, 2022 at 12:30:51 PM UTC-4, amado...@gmail.com wrote: > Jere, ehh.p..., thanks a lot, your complete code was very helpful. > For some reason I tried to write for maps as for vectors and it did not pass. > I see now some forms do pass. > Sorry for the entropy. > As you note, still not possible to access the Key with the "of" form. > > /* > And the form > for (C : My_Maps.Cursor) of My_Map.Iterate loop > does not pass. Must be "in" > */ > > Thanks all. No problem at all. Yeah, all the standard Ada containers use the "of" form to iterate over elements and the "in" form to iterate over cursors. Keys are more like cursors from the perspective of the container, so you would need to use some form of "in" to get the keys. for what it is worth, the example I gave is usable for vectors. you have to change names and use append() instead of insert(), but the rest is pretty similar: ******************************************* with Ada.Text_IO; use Ada.Text_IO; with Ada.Containers.Vectors; procedure Program is package Vectors is new Ada.Containers.Vectors(Positive,Integer); Vector : Vectors.Vector; begin Vector.Append(10); Vector.Append(20); Vector.Append(30); Vector.Append(40); for Element of Vector loop Put_Line(Element'Image); end loop; end Program; ********************************************** Output: 10 20 30 40 ******************************************* IDEONE compiler link: https://ideone.com/3Ic49d#stdout So it may depend on how your vector code was originally setup. The above is how I typically loop through a vector, which works for maps and other Ada containers as well. Hope that helps!