From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: 2-dimensional view on 1 dimensional array
Date: Mon, 24 Oct 2022 03:31:18 -0700 (PDT) [thread overview]
Message-ID: <fd437bfd-a4bd-4c31-b005-bb702f4419f5n@googlegroups.com> (raw)
In-Reply-To: <tj3c6q$178e9$1@dont-email.me>
Your code looks rather ununderstandable to me.
A quick attempt on what you claimed you are trying to do (no guarantee):
generic
type T is private;
type T_Array is array (Integer range <>) of T;
package Dim1_to_2 is
-- type T_Array_2Dim is array (Integer range <>, Integer range <>) of T;
procedure Set (TA: in T_Array; Row, Num_Row, Col, Num_Col: Positive; Value: T)
with Pre => Row in 1 .. Num_Row and Col in 1 .. Num_Col and
Num_Row * Num_col = TA'Length;
end Dim1_to_2;
package body Dim1_to_2 is
type T_Array_2Dim is array (Integer range <>, Integer range <>) of T;
procedure Set (TA: in T_Array; Row, Num_Row, Col, Num_Col: Positive; Value: T) is
TA2: T_Array_2Dim (1 .. Num_Row, 1 .. Num_Col);
for TA2'Address use TA'Address;
begin
if Num_Row * Num_Col /= TA'Length or
Row not in 1 .. Num_Row or Col not in 1 .. Num_Col then
raise Constraint_Error;
end if;
TA2 (Row, Col) := Value;
end Set;
end Dim1_to_2;
with Dim1_to_2;
procedure Ausprobieren is
type A is array (Integer range <>) of Integer;
X: aliased A (-10 .. 10) := (others => 0);
package To_2D is new Dim1_to_2 (Integer, A);
begin
To_2D.Set (X, Row => 2, Num_Row => 7, Col => 1, Num_Col => 3, Value => -1);
for V of X loop
Put_Line (V'Image);
end loop;
next prev parent reply other threads:[~2022-10-24 10:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-23 12:31 2-dimensional view on 1 dimensional array Marek
2022-10-24 10:31 ` AdaMagica [this message]
2022-10-24 10:35 ` AdaMagica
2022-10-25 11:05 ` AdaMagica
2022-10-25 12:57 ` J-P. Rosen
2022-10-25 15:53 ` Jeffrey R.Carter
2022-10-25 19:55 ` J-P. Rosen
-- strict thread matches above, loose matches on Subject: below --
2022-10-25 16:59 Marek
2022-10-26 8:57 ` J-P. Rosen
2022-10-26 15:08 ` AdaMagica
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox