From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9eef6c480abeecf8 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Dynamic array allocation and STL equivalents? Date: Fri, 11 Feb 2005 15:41:39 +0100 Organization: cbb software GmbH Message-ID: <13r5d1sfsg55d$.1u0p9rdnt3zcy.dlg@40tude.net> References: <1108127216.221977.60830@o13g2000cwo.googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: individual.net 4ThD843v119+3qz52X0j9wo2+iyypB8oXqiS2xES56RMnr/0s= User-Agent: 40tude_Dialog/2.0.14.1 Xref: g2news1.google.com comp.lang.ada:8242 Date: 2005-02-11T15:41:39+01:00 List-Id: On 11 Feb 2005 05:06:56 -0800, brian.b.mcguinness@lmco.com wrote: [...] Dynamic allocation of arrays is no problem in Ada. > One interesting project would be to create an object class hierarchy to > implement APL arrays. In APL, the lengths of an array's dimensions can > change, e.g. by concatenating new rows or columns onto a matrix, or > concatenating two matrices, and the number of dimensions can also > change, e.g. by "laminating" two 12x30 arrays to form a 2x12x30 array. > In C++, an obvious solution would be to use STL vectors, e.g.: > > class RealArray { > private: > vector dimensions; > vector data; > public: > // define an indexing operator[] to use the dimensions > // vector to translate sets of indices into offsets > // into the data array Index of a multi-dimensional array is a tuple. That won't work in C++ (you cannot override "," to support: A[i,j,k]). Neither works it in Ada. Though in Ada you could have a type: type Index is array (Integer range <>) of Integer; -- Tuple then in Real_Array: type Real_Array is private; function Get (Container : Real_Array; Element : Index) return Float; private type Index_Ptr is access Index; type Real_Array is new Ada.Finalization.Controlled with record Lower_Bound : Index_Ptr; Upper_Bound : Index_Ptr; Data : ... procedure Finalize (X : in out Real_Array); -- Destructor is a handy thing Then you could index your arrays like: Get (My_Array, (I, J, K)); Further, if you wished to support slices sub-matrices etc, that would require a lot of work. Alas, in Ada you cannot override either "()" or ".." or "in" (membership test) or aggregates. So the interface would be rather clumsy. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de