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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail From: "fabio de francesco" Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: 22 Mar 2005 08:19:28 -0800 Organization: http://groups.google.com Message-ID: <1111508368.393411.6450@z14g2000cwz.googlegroups.com> References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <1110329098.642196@athnrd02> <1110361741.551255@athnrd02> <422edaec$0$26554$9b4e6d93@newsread4.arcor-online.net> <1111464133.508323@athnrd02> NNTP-Posting-Host: 82.49.51.133 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1111508373 6767 127.0.0.1 (22 Mar 2005 16:19:33 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 22 Mar 2005 16:19:33 +0000 (UTC) In-Reply-To: <1111464133.508323@athnrd02> User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=82.49.51.133; posting-account=Lp02jQ0AAABMd3TAghNf0TM2YBZqD_JE Xref: g2news1.google.com comp.lang.ada:9737 comp.lang.c++:46680 comp.realtime:1585 comp.software-eng:5186 Date: 2005-03-22T08:19:28-08:00 List-Id: Ioannis Vranos wrote: > adaworks@sbcglobal.net wrote: > > > OK. Try this in straight C++. > > [skip Ada program] > > I think you mean something like: > > [skip C++ programs] > > > > This is just one example of Ada's flexibility in managing arrays. I could fill > > many pages with > > more examples. Of interest, here, is how easy it is to have an array index > > that begins at > > a value other than zero, and how easy it is to create a function that will > > accept any array > > of any range defined for that index. > > > In C++ you can create whatever you want. Even a container with abstract > conceptual features (you are limited only by your imagination). > > > > Yes, I know you can do this in C++, but > > from my > > perspective, it is not nearly as easy, expressive, or readable. > > > I think even better. That said, I like enough Ada too. :-) > > -- > Ioannis Vranos Ciao, Ioannis wrote a C++ program that in his intentions would had operate like the Ada code that was provided as an example of language expressiveness. Unfortunatelly that C++ code doesn't resembles the Ada one. Have a closer look at what Richard wrote: type Index is range -800_000..12_000_000; type Decimal_Fraction is digits 12 range -473.0 .. 2_000.0; type Vector is array (Index range <>) of Decimal_Fraction; V1 : Vector ( -47..600); -- note the negative index range V2 : Vector (-1.. 10); -- also a negative index range V3 : Vector (42..451); -- index starts higher than zero; He instantiated three arrays that contain elements of type Decimal_Fraction, each of them is 12 or more digits in whatever machine the program can compile and each variable of the type is checked to be in range -473.0 .. 2_000.0. Each single array has a different number of elements and no array with more than 12_800_001 elements is permitted to be created. Furthermore you used a tree (std::map<> is often implemented as a red-black tree) to be read sequentially in searching the second element. I don't think this is the most efficient way to implement what it is better thought to be an array. I mean that if I always have to read every element from the beginning to the end I would prefer to insert them in a vector. Now I remember that you wrote "This is faster than yours scanning the entire range". Now I can be wrong, since I don't know either enough C++ and Ada too, but it seems that you scanned the entire range too. Is it not true? Anyway I suppose that Richard attention was to array declarations and not to function operating on them. Regards, fabio de francesco