In Ada.Containers.{Kind}s of GCC 11.2, I find functions defined<snip>
by the pattern:
function Empty (Capacity : Count_Type := 1000) return {Kind};
I couldn't find these functions in the LRM's package specifications.
Am I missing something?
On Wednesday, September 14, 2022 at 2:36:11 PM UTC+2, G.B. wrote:
<snip>
I couldn't find these functions in the LRM's package specifications.
Am I missing something?
They're part of Ada 2022, needed for the new container aggregate syntax.
See,
http://www.ada-auth.org/standards/2xrm/html/RM-A-18-5.html http://www.ada-auth.org/standards/2xrm/html/RM-4-3-5.html
... it seems best to have compilers for pre-202x at hand
in case a program needs Ada 2005 containers or Ada 2012 containers. (G.B.)
... it seems best to have compilers for pre-202x at hand in case a
program needs Ada 2005 containers or Ada 2012 containers. (G.B.)
Sorry, but is all this new stuff not backward-compatible? (Except
maybe a teeny thing or two, easy to fix.)
BTW, do the new containers fix map iteration? I'm always stupefied at
not being possible to iterate a map like you do a vector.
... There are functions First and Next ... procedure Iterate ...
"for X of M loop ... end loop".
Thanks, Niklas.
... There are functions First and Next ... procedure Iterate ...
Too verbose and error-prone (forget the Next and you get an endless loop).
Thanks, Niklas.
... There are functions First and Next ... procedure Iterate ...
Too verbose and error-prone (forget the Next and you get an endless loop).
"for X of M loop ... end loop".
Not possible for maps.
https://programming-idioms.org/idiom/13/iterate-over-map-keys-and-value/1511/ada>
"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;
"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;Thanks, but this is "in", not "of", requires cursors, and DOES NOT COMPILE, as probably needs like ten lines of boiler plate not show.
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, Niklas.
... There are functions First and Next ... procedure Iterate ...
Too verbose and error-prone (forget the Next and you get an endless loop).
"for X of M loop ... end loop".Not possible for maps.
That is cursors/iterators for you. They are nothing but dressed up
pointers. Should never be there, IMO. (Dmitry)
In my containers I use positive index 1..<size> instead.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Jere, ehh.p..., thanks a lot, your complete code was very helpful.No problem at all. Yeah, all the standard Ada containers use the "of" form to iterate
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.
but you can as"for X of M loop ... end loop".
Not possible for maps.
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.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 399 |
Nodes: | 16 (3 / 13) |
Uptime: | 64:45:36 |
Calls: | 8,355 |
Calls today: | 15 |
Files: | 13,159 |
Messages: | 5,893,806 |
Posted today: | 1 |