From: "Björn Lundin" <b.f.lundin@gmail.com>
Subject: Re: container of a container...
Date: Sat, 01 Aug 2015 13:56:46 +0200
Date: 2015-08-01T13:56:46+02:00 [thread overview]
Message-ID: <mpibvk$t5c$1@dont-email.me> (raw)
In-Reply-To: <790f92b6-56fc-4dfb-81c7-39b11a1b9ae0@googlegroups.com>
On 2015-07-31 23:13, Hedley Rainnie wrote:
> Is it possible to code that? I am coming from the C++ STL world where, it relatively easy to put that together. (a vector of lists as an example).
>
> There are many wonderful examples for Ada containers (stacks etc). But I have not seen any container[container[...]..] examples.
>
> Being new to Ada, I am sure I have missed something obvious...
>
>
--Below creates a map, keyed on 2 character length strings
--and hold a list of integers;
--it also prints the items of each list in the two map-entries
with Ada.Containers.Doubly_Linked_Lists;
with Ada.Containers.Hashed_Maps;
with Ada.Strings;
with Ada.Strings.Hash;
with Text_Io;
procedure Lists is
package Integer_Pack is new Ada.Containers.Doubly_Linked_Lists(integer);
subtype String_Key_Type is String(1..2);
package List_Maps is new Ada.Containers.Hashed_Maps (
String_Key_Type,
Integer_Pack.List,
Ada.Strings.Hash,
"=",
Integer_Pack."=");
Map : List_Maps.Map ;
Integer_List : Integer_Pack.List;
begin
for i in 1 .. 20 loop
Integer_List.Append(i);
end loop;
Map.Insert("12", Integer_List);
Integer_List.Clear;
for i in 21 .. 40 loop
Integer_List.Append(i);
end loop;
Map.Insert("11", Integer_List);
for L of map("11") loop
Text_Io.Put_Line(L'img);
end loop;
for L of map("12") loop
Text_Io.Put_Line(L'img);
end loop;
end Lists;
--
--
Björn
prev parent reply other threads:[~2015-08-01 11:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-31 21:13 container of a container Hedley Rainnie
2015-07-31 21:48 ` Niklas Holsti
2015-08-01 11:56 ` Björn Lundin [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox