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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c406e0c4a6eb74ed X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews2.google.com!not-for-mail From: kevin.cline@gmail.com (Kevin Cline) Newsgroups: comp.lang.ada Subject: Re: ADA Popularity Discussion Request Date: 14 Sep 2004 09:50:04 -0700 Organization: http://groups.google.com Message-ID: References: <49dc98cf.0408110556.18ae7df@posting.google.com> <413e2fbd$0$30586$626a14ce@news.free.fr> NNTP-Posting-Host: 198.23.26.253 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1095180605 10312 127.0.0.1 (14 Sep 2004 16:50:05 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 14 Sep 2004 16:50:05 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:3728 Date: 2004-09-14T09:50:04-07:00 List-Id: Georg Bauhaus wrote in message news:... > Kevin Cline wrote: > > : I don't know. It could be done in C++ if Some_Index_Type had the > : right properties. But as a practical matter, no one seems to care, at > : least no one in the C++ community. > > Could it be an effect of tradition? If C++ had not inherited C arrays, > maybe arrays (including dynamically sized) were used more frequently? > I guess vector is used for array computation, then? I'm not sure what you mean by "array computation". For mathematical vectors and matrices with dot product and matrix multiplication you would want a template based library, and such libraries do exist. C++ is an excellent language for writing such a library, because template functions can instantiate new types automatically, e.g. template matrix operator*(const matrix& lhs, conat matrix& rhs) {...} template vec trace(const matrix& m) { ... } template matrix outer_product(const vec& v1, const vec& v2) { ... } Now I can write code like this: matrix<3,5> func(const matrix<3,5>& m1, const matrix<5,3>& m2) { return outer_product(trace(m1*m2), trace(m2*m1)); } You could do the same in Ada, but first you would have to explicitly instantiate the five functions. That gets old really fast. This ground is covered extensively in Scientific and Engineering C++ : An Introduction with Advanced Techniques and Examples by John J. Barton, Lee R. Nackman. > > : I very rarely have any need or use > : for a statically sized array. > > If you need _dynamically_ sized arrays you still can have subtypes with > bounds determined at run time. I think this can be important. (C99 now > has some of it.) Declare the subtypes locally as index types, ranges > based on runtime values. Declare dynamically or statically sized arrays > in blocks, in functions, wherever. Create corresponding arrays on the > stack or on the heap, assign the results ... > > > type Vec is array (Positive range <>) of Natural; > -- base type of all "vectors" counting from 1 > > function make(limit: Positive; init: Natural := 0) return Vec > -- a dynamically sized `Vec`, all values set to `init` > is > subtype Index is Positive range Positive'first .. limit; > subtype A is Vec(Index); > begin > return A'(others => init); > end make; > > x: Vec := make(5); But even though X has a run-time determined size, its size is now fixed. I can neither add or remove elements without creating an entirely new vector.