The extension on Shark8 is a bit here ...
Ada allows you to declare array types without restriction. Sort of
type Array_of_Records is array (Natural range <>) of My_Record;
Gives you a type that you can use for record arrays with start and end indexes of arrays that can be in any range of Natural .
One of the great things I can do with this type is to use it as a subroutine parameter, for example:
function Sum (Vector : in Array_of_Records) return Natural;
OK, so inside this procedure, how do I know where the boundaries of the array are? Using attributes, for example:
for index in Vector'first..Vector'last loop
or
for index in Vector'range loop
Of course, for this to work, you must pass an array of size to your class. Assume that this is not what you have. Suppose you instead have a huge array (kind of buffer), and not all values are valid? Well, you keep track of the actual values and skip only those using the slice.
Rec_Buffer : Array_of_Records (1..10_000); Last_Valid_Rec : Natural := 0; .... --// Rec_Buffer gets loaded with 2,128 values or something. We pass it into Sum --// like so: Ada.Text_IO ("Sum of vector is " & natural'image(Sum (Rec_Buffer (1..Last_Valid_Rec));
(warning - not compiled code)
source share