* container of a container...
@ 2015-07-31 21:13 Hedley Rainnie
2015-07-31 21:48 ` Niklas Holsti
2015-08-01 11:56 ` Björn Lundin
0 siblings, 2 replies; 3+ messages in thread
From: Hedley Rainnie @ 2015-07-31 21:13 UTC (permalink / raw)
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...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: container of a container...
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
1 sibling, 0 replies; 3+ messages in thread
From: Niklas Holsti @ 2015-07-31 21:48 UTC (permalink / raw)
On 15-08-01 00: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...
Example of a vector of lists of characters:
with Ada.Containers.Vectors;
with Ada.Containers.Doubly_Linked_Lists;
procedure Vec_List
is
package Char_Lists is new Ada.Containers.Doubly_Linked_Lists (
Element_Type => Character);
package Char_List_Vectors is new Ada.Containers.Vectors (
Index_Type => Positive,
Element_Type => Char_Lists.List,
"=" => Char_Lists."=");
Vec : Char_List_Vectors.Vector;
ABC : Char_Lists.List;
begin
ABC.Append ('A');
ABC.Append ('B');
ABC.Append ('C');
Vec.Replace_Element (3, ABC);
end Vec_List;
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: container of a container...
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
1 sibling, 0 replies; 3+ messages in thread
From: Björn Lundin @ 2015-08-01 11:56 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-01 11:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox