On this page
- Availability and ownership
- Import and instantiate
- Contract and lifecycle reading
- API 001
- API 002
- API 003
- API 004
- API 005
- API 006
- API 007
- API 008
- API 009
- API 010
- API 011
- API 012
- API 013
- API 014
- API 015
- API 016
- API 017
- API 018
- API 019
- API 020
- API 021
- API 022
- API 023
- API 024
- API 025
- API 026
- API 027
- API 028
- API 029
- API 030
- API 031
- API 032
- API 033
- API 034
- API 035
- API 036
- API 037
- API 038
Ada.Containers.Bounded_Vectors
Vectors of at most Capacity elements, indexed from Index_Type'First (RM A.18.19).
Read the family guide for representation, selection and resource rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.
Availability and ownership
Ada's generic formals and a capacity discriminant, in the design of Verada.Containers.Formal: contracts at every place over a ghost functional model; preconditions where Ada raises Constraint_Error or Capacity_Error. Instantiate it as Ada's, as in package P is new Ada.Containers.Bounded_Vectors (Positive, Integer);, and declare objects with their capacity. Elements are reached by index; there are no cursors.
A client proof uses these contracts without proving the body again (see library assurance). Global => null excludes package-global effects, not changes made through an in out argument.
Import and instantiate
with Ada.Containers.Bounded_Vectors;import Ada.Containers.Bounded_Vectors;
A Vibe module imports this unit's names with from Ada.Containers.Bounded_Vectors import Name; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.
Contract and lifecycle reading
A Pre condition is the caller's obligation; a Post is what a normal return guarantees. What a postcondition does not state, a client cannot assume. Ghost functions are for contracts and ghost code. The family guide describes copying, lifetime, order and cost.
API 001
Index_Type (declaration) — The generic formals, as Ada's: the instance's types and the operations it compares with.
Declared interface:
generic
type Index_Type is range <>;
type Element_Type is private;
with function "=" (Left, Right : Element_Type) return Boolean is <>;API 002
Extended_Index (declaration) — The indices and the one before the first, which No_Index is.
Declared interface:
subtype Extended_Index is Index_Type'Base range Index_Type'First - 1 .. Index_Type'Last;API 003
No_Index (declaration) — The index before the first: Find_Index's result when nothing matches.
Declared interface:
No_Index : constant Extended_Index := Extended_Index'First;API 004
Index_Count (declaration) — How many indices Index_Type has: the most elements a vector holds, whatever its capacity.
Declared interface:
Index_Count : constant Long_Long_Long_Integer :=
Long_Long_Long_Integer'Max (0, Long_Long_Long_Integer (Index_Type'Last) - Long_Long_Long_Integer (Index_Type'First) + 1);API 005
Vector (declaration) — The vector type, with its capacity as a discriminant; a new vector is empty.
Declared interface:
type Vector (Capacity : Count_Type) is private
with Default_Initial_Condition => Length (Vector) = 0,
Iterable => (First => Iter_First, Next => Iter_Next, Has_Element => Iter_Has_Element, Element => Iter_Element);API 006
Length (declaration) — The number of elements (or entries) the container holds now.
Declared interface:
function Length (Container : Vector) return Count_Type
with Global => null,
Post => Length'Result <= Container.Capacity and then Long_Long_Long_Integer (Length'Result) <= Index_Count;API 007
Empty (declaration) — The vector of no elements, with room for Capacity.
Declared interface:
function Empty (Capacity : Count_Type := 10) return Vector
with Global => null,
Post => Empty'Result.Capacity = Capacity and then Length (Empty'Result) = 0;API 008
Is_Empty (declaration) — Whether the container holds nothing.
Declared interface:
function Is_Empty (Container : Vector) return Boolean is (Length (Container) = 0);API 009
First_Index (declaration) — The first index, Index_Type'First.
Declared interface:
function First_Index (Container : Vector) return Index_Type is (Index_Type'First);API 010
Last_Index (declaration) — The index of the last element, No_Index when there is none.
Declared interface:
function Last_Index (Container : Vector) return Extended_Index
with Global => null,
Post => Long_Long_Long_Integer (Last_Index'Result)
= Long_Long_Long_Integer (Index_Type'First) - 1 + Long_Long_Long_Integer (Length (Container));API 011
Element (declaration) — The element at the given index, cursor or key; the precondition requires one to be there.
Declared interface:
function Element (Container : Vector; Index : Index_Type) return Element_Type
with Global => null,
Pre => Index <= Last_Index (Container);API 012
Position (declaration) — The place of an index's element in the model, from 1.
Declared interface:
function Position (Index : Index_Type) return Long_Long_Long_Integer is
(Long_Long_Long_Integer (Index) - Long_Long_Long_Integer (Index_Type'First) + 1);API 013
Models (declaration) — The functional model: the elements in order, as a sequence.
Declared interface:
package Models is new Verada.Containers.Functional.Sequences (Element_Type);API 014
Model (declaration) — Ghost: the functional model of the contents, in order, for contracts.
Declared interface:
function Model (Container : Vector) return Models.Sequence
with Ghost,
Global => null,
Post => Models.Length (Model'Result) = Natural (Length (Container))
and then (for all I in Index_Type'First .. Last_Index (Container) =>
Models.Equal_Elements (Models.Get (Model'Result, Positive (Position (I))), Element (Container, I)));API 015
Same_Elements (declaration) — Left and Right hold the same elements in the same order (their capacities may differ).
Declared interface:
function Same_Elements (Left, Right : Vector) return Boolean is
(Length (Left) = Length (Right)
and then (for all I in Index_Type'First .. Last_Index (Left) => Models.Equal_Elements (Element (Left, I), Element (Right, I))))
with Ghost;API 016
First_Element (declaration) — The first element; the container must not be empty.
Declared interface:
function First_Element (Container : Vector) return Element_Type
with Global => null,
Pre => not Is_Empty (Container),
Post => Models.Equal_Elements (First_Element'Result, Element (Container, Index_Type'First));API 017
Last_Element (declaration) — The last element; the container must not be empty.
Declared interface:
function Last_Element (Container : Vector) return Element_Type
with Global => null,
Pre => not Is_Empty (Container),
Post => Models.Equal_Elements (Last_Element'Result, Element (Container, Last_Index (Container)));API 018
Clear (declaration) — Empties the container; its capacity is unchanged.
Declared interface:
procedure Clear (Container : in out Vector)
with Global => null,
Post => Length (Container) = 0;API 019
Replace_Element (declaration) — Puts New_Item in place of the element there; everything else is unchanged.
Declared interface:
procedure Replace_Element (Container : in out Vector; Index : Index_Type; New_Item : Element_Type)
with Global => null,
Pre => Index <= Last_Index (Container),
Post => Length (Container) = Length (Container)'Old
and then Models.Equal_Elements (Element (Container, Index), New_Item)
and then (for all I in Index_Type'First .. Last_Index (Container) =>
(if I /= Index then Models.Equal_Elements (Element (Container, I), Element (Container'Old, I))));API 020
Append (declaration) — Adds New_Item at the end; the precondition requires room.
Declared interface:
procedure Append (Container : in out Vector; New_Item : Element_Type)
with Global => null,
Pre => Length (Container) < Container.Capacity and then Last_Index (Container) < Index_Type'Last,
Post => Length (Container) = Length (Container)'Old + 1
and then Models.Equal_Elements (Element (Container, Last_Index (Container)), New_Item)
and then (for all I in Index_Type'First .. Last_Index (Container'Old) =>
Models.Equal_Elements (Element (Container, I), Element (Container'Old, I)));API 021
Insert (declaration) — New_Item before the element at Before (at the end when Before is Last_Index + 1).
Declared interface:
procedure Insert (Container : in out Vector; Before : Extended_Index; New_Item : Element_Type)
with Global => null,
Pre => Length (Container) < Container.Capacity and then Last_Index (Container) < Index_Type'Last
and then Before >= Index_Type'First and then Before <= Last_Index (Container) + 1,
Post => Length (Container) = Length (Container)'Old + 1
and then Models.Equal_Elements (Element (Container, Before), New_Item)
and then (for all I in Index_Type'First .. Last_Index (Container'Old) =>
(if I < Before then Models.Equal_Elements (Element (Container, I), Element (Container'Old, I))
else Models.Equal_Elements (Element (Container, I + 1), Element (Container'Old, I))));API 022
Prepend (declaration) — Adds New_Item at the start; the precondition requires room.
Declared interface:
procedure Prepend (Container : in out Vector; New_Item : Element_Type)
with Global => null,
Pre => Length (Container) < Container.Capacity and then Last_Index (Container) < Index_Type'Last,
Post => Length (Container) = Length (Container)'Old + 1
and then Models.Equal_Elements (Element (Container, Index_Type'First), New_Item)
and then (for all I in Index_Type'First .. Last_Index (Container'Old) =>
Models.Equal_Elements (Element (Container, I + 1), Element (Container'Old, I)));API 023
Delete (declaration) — The element at Index goes; those after it move down one.
Declared interface:
procedure Delete (Container : in out Vector; Index : Extended_Index)
with Global => null,
Pre => Index >= Index_Type'First and then Index <= Last_Index (Container),
Post => Length (Container) = Length (Container)'Old - 1
and then (for all I in Index_Type'First .. Last_Index (Container) =>
(if I < Index then Models.Equal_Elements (Element (Container, I), Element (Container'Old, I))
else Models.Equal_Elements (Element (Container, I), Element (Container'Old, I + 1))));API 024
Delete_First (declaration) — Removes the first element; the container must not be empty.
Declared interface:
procedure Delete_First (Container : in out Vector)
with Global => null,
Pre => not Is_Empty (Container),
Post => Length (Container) = Length (Container)'Old - 1
and then (for all I in Index_Type'First .. Last_Index (Container) =>
Models.Equal_Elements (Element (Container, I), Element (Container'Old, I + 1)));API 025
Delete_Last (declaration) — Removes the last element; the container must not be empty.
Declared interface:
procedure Delete_Last (Container : in out Vector)
with Global => null,
Pre => not Is_Empty (Container),
Post => Length (Container) = Length (Container)'Old - 1
and then (for all I in Index_Type'First .. Last_Index (Container) =>
Models.Equal_Elements (Element (Container, I), Element (Container'Old, I)));API 026
Swap (declaration) — The elements at I and J change places.
Declared interface:
procedure Swap (Container : in out Vector; I, J : Index_Type)
with Global => null,
Pre => I <= Last_Index (Container) and then J <= Last_Index (Container),
Post => Length (Container) = Length (Container)'Old
and then Models.Equal_Elements (Element (Container, I), Element (Container'Old, J))
and then Models.Equal_Elements (Element (Container, J), Element (Container'Old, I))
and then (for all K in Index_Type'First .. Last_Index (Container) =>
(if K /= I and then K /= J then Models.Equal_Elements (Element (Container, K), Element (Container'Old, K))));API 027
Reverse_Elements (declaration) — The elements in the opposite order.
Declared interface:
procedure Reverse_Elements (Container : in out Vector)
with Global => null,
Post => Length (Container) = Length (Container)'Old
and then (for all I in Index_Type'First .. Last_Index (Container) =>
Models.Equal_Elements
(Element (Container, I),
Element (Container'Old, Index_Type'First + (Last_Index (Container) - I))));API 028
Find_Index (declaration) — The first index from Index on whose element is Item ("="), or No_Index.
Declared interface:
function Find_Index (Container : Vector; Item : Element_Type; Index : Index_Type := Index_Type'First) return Extended_Index
with Global => null,
Post => (if Find_Index'Result = No_Index
then (for all I in Index .. Last_Index (Container) => not (Element (Container, I) = Item))
else Find_Index'Result >= Index and then Find_Index'Result <= Last_Index (Container)
and then Element (Container, Find_Index'Result) = Item
and then (for all I in Index .. Find_Index'Result - 1 => not (Element (Container, I) = Item)));API 029
Reverse_Find_Index (declaration) — The last index up to Index whose element is Item ("="), or No_Index.
Declared interface:
function Reverse_Find_Index (Container : Vector; Item : Element_Type; Index : Index_Type := Index_Type'Last) return Extended_Index
with Global => null,
Post => (if Reverse_Find_Index'Result = No_Index
then (for all I in Index_Type'First .. Extended_Index'Min (Index, Last_Index (Container)) => not (Element (Container, I) = Item))
else Reverse_Find_Index'Result <= Index and then Reverse_Find_Index'Result <= Last_Index (Container)
and then Element (Container, Reverse_Find_Index'Result) = Item
and then (for all I in Index_Type'First .. Extended_Index'Min (Index, Last_Index (Container)) =>
(if I > Reverse_Find_Index'Result then not (Element (Container, I) = Item))));API 030
Contains (declaration) — Whether the container holds an element (or key) matching the argument.
Declared interface:
function Contains (Container : Vector; Item : Element_Type) return Boolean is
(Find_Index (Container, Item) /= No_Index);API 031
"=" (declaration) — The same length and elements equal ("=") index by index.
Declared interface:
function "=" (Left, Right : Vector) return Boolean
with Global => null,
Post => "="'Result = (Length (Left) = Length (Right)
and then (for all I in Index_Type'First .. Last_Index (Left) => Element (Left, I) = Element (Right, I)));API 032
Assign (declaration) — Target holds Source's elements.
Declared interface:
procedure Assign (Target : in out Vector; Source : Vector)
with Global => null,
Pre => Length (Source) <= Target.Capacity,
Post => Same_Elements (Target, Source);API 033
Copy (declaration) — A vector of Source's elements with room for Capacity, or for Source's length when Capacity is 0.
Declared interface:
function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector
with Global => null,
Pre => Capacity = 0 or else Capacity >= Length (Source),
Post => Copy'Result.Capacity = (if Capacity = 0 then Length (Source) else Capacity)
and then Same_Elements (Copy'Result, Source);API 034
To_Vector (declaration) — Length copies of New_Item.
Declared interface:
function To_Vector (New_Item : Element_Type; Length : Count_Type) return Vector
with Global => null,
Pre => Long_Long_Long_Integer (Length) <= Index_Count,
Post => To_Vector'Result.Capacity = Length
and then Bounded_Vectors.Length (To_Vector'Result) = Length
and then (for all I in Index_Type'First .. Last_Index (To_Vector'Result) =>
Models.Equal_Elements (Element (To_Vector'Result, I), New_Item));API 035
Iter_First (declaration) — for E of V and for all E of V =>...: positions 1 .. Length (V).
Declared interface:
function Iter_First (Container : Vector) return Count_Type is (1);API 036
Iter_Next (declaration) — Iteration support: the position after another.
Declared interface:
function Iter_Next (Container : Vector; Position : Count_Type) return Count_Type is
(if Position < Count_Type'Last then Position + 1 else Position);API 037
Iter_Has_Element (declaration) — Iteration support: whether a position holds an element.
Declared interface:
function Iter_Has_Element (Container : Vector; Position : Count_Type) return Boolean is
(Position in 1 .. Length (Container));API 038
Iter_Element (declaration) — Iteration support: the element at a position.
Declared interface:
function Iter_Element (Container : Vector; Position : Count_Type) return Element_Type
with Global => null,
Pre => Iter_Has_Element (Container, Position);