I have an array in a generic function where I want to iterate through it byte by byte. In the following example I am using Wide_Wide_Character
‘s, so a character is 4 bytes long. With 3 given input characters, I would have 12 bytes to iterate through. How can I achieve this? Thanks for your time.
<code>with Ada.Text_IO;
procedure Test is
generic
type T is (<>);
type T_Index is range <>;
type T_Array is array (T_Index range <>) of T;
function A (b : T_Array) return Integer;
function A (b : T_Array) return Integer is
begin
-- how can I iterate here through each byte instead of "byte blocks"?
-- should be 12 bytes in this example (3 characters * 4 bytes)
-- can I map b to System.Storage_Elements.Storage_Array (without copying it)?
for I in 1 .. b'Length loop
Ada.Text_IO.Put_Line (b (T_Index (I))'Image);
end loop;
return 1;
end A;
function A1 is new A (Wide_Wide_Character, Positive, Wide_Wide_String);
unused : Integer := A1 ("abc");
begin
null;
end Test;
</code>
<code>with Ada.Text_IO;
procedure Test is
generic
type T is (<>);
type T_Index is range <>;
type T_Array is array (T_Index range <>) of T;
function A (b : T_Array) return Integer;
function A (b : T_Array) return Integer is
begin
-- how can I iterate here through each byte instead of "byte blocks"?
-- should be 12 bytes in this example (3 characters * 4 bytes)
-- can I map b to System.Storage_Elements.Storage_Array (without copying it)?
for I in 1 .. b'Length loop
Ada.Text_IO.Put_Line (b (T_Index (I))'Image);
end loop;
return 1;
end A;
function A1 is new A (Wide_Wide_Character, Positive, Wide_Wide_String);
unused : Integer := A1 ("abc");
begin
null;
end Test;
</code>
with Ada.Text_IO;
procedure Test is
generic
type T is (<>);
type T_Index is range <>;
type T_Array is array (T_Index range <>) of T;
function A (b : T_Array) return Integer;
function A (b : T_Array) return Integer is
begin
-- how can I iterate here through each byte instead of "byte blocks"?
-- should be 12 bytes in this example (3 characters * 4 bytes)
-- can I map b to System.Storage_Elements.Storage_Array (without copying it)?
for I in 1 .. b'Length loop
Ada.Text_IO.Put_Line (b (T_Index (I))'Image);
end loop;
return 1;
end A;
function A1 is new A (Wide_Wide_Character, Positive, Wide_Wide_String);
unused : Integer := A1 ("abc");
begin
null;
end Test;