Ниже приведен пример использования контейнера Vector.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Vectors;
procedure Main is
type Surname is (Smith, Jones, Chen, Chavez);
type Name is (John, Francis, Leslie, Margaret, George, Walter);
type Person is record
First : Name;
Last : Surname;
end record;
function Less(P1: Person; P2 : Person) return boolean is
begin
if P1.Last < P2.Last then
return true;
elsif
P1.Last = P2.Last then
return P1.First < P2.First;
else
return false;
end if;
end Less;
procedure Print(P : Person) is
begin
Put_Line(P.Last'Image & ", " & P.First'Image);
end Print;
package Person_Vector is new Ada.Containers.Vectors(Index_Type => Natural,
Element_Type => Person);
use Person_Vector;
package Person_Sort is new Generic_Sorting(Less);
use Person_Sort;
V : Vector;
Temp : Person;
begin
for N in Name loop
for S in Surname loop
Temp.First := N;
Temp.Last := S;
V.Append(Temp);
end loop;
end loop;
Put_Line("Unsorted list:");
for P of V loop
Print(P);
end loop;
New_Line;
Sort(V);
Put_Line("Sorted list:");
for P of V loop
Print(P);
end loop;
end Main;
Вывод этой программы:
Unsorted list:
SMITH, JOHN
JONES, JOHN
CHEN, JOHN
CHAVEZ, JOHN
SMITH, FRANCIS
JONES, FRANCIS
CHEN, FRANCIS
CHAVEZ, FRANCIS
SMITH, LESLIE
JONES, LESLIE
CHEN, LESLIE
CHAVEZ, LESLIE
SMITH, MARGARET
JONES, MARGARET
CHEN, MARGARET
CHAVEZ, MARGARET
SMITH, GEORGE
JONES, GEORGE
CHEN, GEORGE
CHAVEZ, GEORGE
SMITH, WALTER
JONES, WALTER
CHEN, WALTER
CHAVEZ, WALTER
Sorted list:
SMITH, JOHN
SMITH, FRANCIS
SMITH, LESLIE
SMITH, MARGARET
SMITH, GEORGE
SMITH, WALTER
JONES, JOHN
JONES, FRANCIS
JONES, LESLIE
JONES, MARGARET
JONES, GEORGE
JONES, WALTER
CHEN, JOHN
CHEN, FRANCIS
CHEN, LESLIE
CHEN, MARGARET
CHEN, GEORGE
CHEN, WALTER
CHAVEZ, JOHN
CHAVEZ, FRANCIS
CHAVEZ, LESLIE
CHAVEZ, MARGARET
CHAVEZ, GEORGE
CHAVEZ, WALTER
Обратите внимание, что поля отсортированы в порядке, указанном их перечисленияв программе.