Ada: Standard Library
The Ada standard defines the library with the language — Ada.* namespaces are portable across every compiler. This tour covers the three families you will use constantly: containers, numerics, and the string/character utilities.
Containers
Ada.Containers provides generic, type-safe collections. They are formal packages — you instantiate them for your element type, and every operation is checked:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Vectors;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
procedure Container_Demo is
-- a vector of unbounded strings: Positive is the index subtype
package Name_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive, Element_Type => Unbounded_String);
use Name_Vectors;
Names : Vector;
begin
Names.Append (To_Unbounded_String ("Ada"));
Names.Append (To_Unbounded_String ("Jean"));
Names.Append (To_Unbounded_String ("Tucker"));
-- iterate with a cursor or a plain loop over the index range
for I in Names.First_Index .. Names.Last_Index loop
Put_Line (To_String (Names (I)));
end loop;
Put_Line (Natural'Image (Length (Names)) & " names");
end Container_Demo;
The family covers the standard structures — all with the same instantiate-then-use pattern:
| Container | Package | Notes |
|---|---|---|
| Vector | Ada.Containers.Vectors | growable array, O(1) index |
| Doubly linked list | Ada.Containers.Doubly_Linked_Lists | stable cursors, O(1) splice |
| Hashed map | Ada.Containers.Hashed_Maps | key → element, user hash |
| Ordered map | Ada.Containers.Ordered_Maps | sorted traversal, no hash needed |
| Sets | Hashed_Sets, Ordered_Sets | membership, set algebra |
| Queues | Unbounded_Priority_Queues | tasking-ready priority queues |
Cursors (Container.First, Next (C)) traverse without invalidating on append for lists; vectors invalidate on reallocation — the docs state which operations invalidate, precisely.