comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Non-standard functions in GNAT's Ada.Containers packages?
Date: Fri, 16 Sep 2022 10:08:22 -0700 (PDT)	[thread overview]
Message-ID: <aa33dc02-64ce-40a0-9134-6b38d7bef8d3n@googlegroups.com> (raw)
In-Reply-To: <ffc943e5-8870-43d2-8deb-64c16cec5947n@googlegroups.com>

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!

  reply	other threads:[~2022-09-16 17:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 12:36 Non-standard functions in GNAT's Ada.Containers packages? G.B.
2022-09-14 16:04 ` Egil H H
2022-09-15  7:13   ` G.B.
2022-09-15 14:26     ` Marius Amado-Alves
2022-09-15 15:03       ` Niklas Holsti
2022-09-15 17:11         ` Marius Amado-Alves
2022-09-15 17:22           ` Dmitry A. Kazakov
2022-09-16 16:03             ` Marius Amado-Alves
2022-09-16 16:30               ` Marius Amado-Alves
2022-09-16 17:08                 ` Jere [this message]
2022-09-16 11:33           ` Björn Lundin
2022-09-16 15:00             ` Marius Amado-Alves
2022-09-16 15:42               ` Egil H H
2022-09-16 18:53               ` Björn Lundin
2022-09-16 15:47           ` Jere
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox