-- This package simulates single dimensioned arrays.  The
-- type declaration for the array would look like (using the formals below)
--      type XXX is array (index) of element_ptr;
-- This generic is intended to replace the array as cleanly as possible.
-- An example of how this can be done is:
--   Without the generic, one would typically declare the array as
--      foo:XXX
--   This construct can be simulated by
--      function foo(x:index) return element_ptr renames generic.fetch

-- The values returned always point at a valid element, either initialized
-- as per the element type declaration, or one existing from some other access.

-- The storage is allocated as needed on the 'heap' provided.
-- 'Heap' must be initialized when the generic is instantiated. In many
-- cases, job_segment.get can be used as the initializer for 'heap'

with System;

generic
    type Element is private;

    type Element_Ptr is access Element;
    pragma Segmented_Heap (Element_Ptr);
    pragma Short_Pointer (Element_Ptr);

    type Index is range <>;

    Heap : System.Segment;
package Ersatz_Array_Generic is
    function Fetch (N : Index) return Element_Ptr;
    procedure Exchange (A, B : Index);
end Ersatz_Array_Generic;