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,bb7cc916bd63ab43 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!border1.nntp.ams.giganews.com!nntp.giganews.com!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Performance of element access in Vector Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <0a8baaf0-19f7-40c0-a041-884e93fa7020@w39g2000prb.googlegroups.com> <1fp3pbmn4q3o5.1b0fk6lircbld.dlg@40tude.net> <12j12r8i016ec$.7w03wnt52mdi$.dlg@40tude.net> <15dd6f2b-0d9d-42d0-9c7a-c17bc348434f@x16g2000prn.googlegroups.com> Date: Wed, 21 Jan 2009 20:00:56 +0100 Message-ID: NNTP-Posting-Date: 21 Jan 2009 20:00:58 CET NNTP-Posting-Host: cbb5ffb8.newsspool2.arcor-online.net X-Trace: DXC=eUWbh^4h9__1`E>oC;JXEZA9EHlD;3YcR4Fo<]lROoRQ^YC2XCjHcbYEL]HnTCTDNcfSJ;bb[UIRnRBaCd On Wed, 21 Jan 2009 05:14:17 -0800 (PST), Maciej Sobczak wrote: > On 21 Sty, 11:19, "Dmitry A. Kazakov" > wrote: > >>> You mean that arrays have the Iterate method? >> >> The language Ada has iteration methods, for example for-loop. > > No, for-loops are not iteration methods, they are control structures. They are methods of iteration. You mean that for-loop is not a primitive operation of array. Why should it be? > Iteration methods are defined by particular interfaces and these are > different for arrays and Vectors. Yes, as an ugly hack container libraries provide "foreach" as a primitive operation. It is even so ugly because neither Ada nor C++ support multiple dispatch in order to make such a primitive operation truly primitive for both the container and the element, or maybe for three, including index/cursor. >>>> Ordered containers must have array interface. >> >>> You mean that containers overload the () indexing? I'm afraid they don't. >> >> That containers implement element access using an index from 1D space, if >> we are talking about iterations. > > This similarity can be interesting as a theory, but is useless in > practice. I don't see any problems. For-loops were in practical use long before any container libraries. > Can you *reuse* a piece of code that traverses an array (or Vector) > and apply it to a Vector (or array, respectively)? You wrap for-loop into a procedure, that is. > There are two reuse mechanisms in Ada, one with class-wide types and > run-time polymorphism and one with generics. Neither one can be > applied to the arrays vs. Vectors problem. Why? It is trivial to define a primitive operation containing a loop. > That's why, as far as I'm concerned, arrays and Vectors do not share > any interface. They shall share array interface when ordered. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de