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 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!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!t-online.de!tsicnews.teliasonera.com!news.otenet.gr!news.grnet.gr!newsfd02.forthnet.gr!not-for-mail From: Ioannis Vranos Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: Tue, 22 Mar 2005 06:02:13 +0200 Organization: FORTHnet S.A., Atthidon 4, GR-17671 Kalithea, Greece, Tel: +30 2109559000, Fax: +30 2109559333, url: http://www.forthnet.gr Message-ID: <1111464133.508323@athnrd02> 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> NNTP-Posting-Host: athnrd02.forthnet.gr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: athprx02.forthnet.gr 1111464133 13937 193.92.150.73 (22 Mar 2005 04:02:13 GMT) X-Complaints-To: abuse@forthnet.gr NNTP-Posting-Date: Tue, 22 Mar 2005 04:02:13 +0000 (UTC) User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en In-Reply-To: Cache-Post-Path: newsfd02!unknown@ppp14-adsl-66.ath.forthnet.gr Xref: g2news1.google.com comp.lang.ada:9710 comp.lang.c++:46641 comp.realtime:1579 comp.software-eng:5180 Date: 2005-03-22T06:02:13+02:00 List-Id: adaworks@sbcglobal.net wrote: > OK. Try this in straight C++. > > 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; > ............................... > > function Scan (The_Vector : Vector ; Scan_Value : Decimal_Fraction ) > return Natural; > -- This function can process any of those vector instances > without modification > ............................. > -- possible implementation of the function > function Scan(The_Vector : Vector; Scan_Value : Decimal_Fraction ) > return Natrual is > Scan_Count : Natural := 0; -- Natual begins at zero > begin > for I in The_Vector'Range -- No way to index off the end array > parameter > loop > if The_Vector(I) = Scan_Value; -- looking for an > exact match > Scan_Count := Scan_Count + 1; -- increment the count > end if; > end loop; > return Scan_Count; -- return required; never an implicit > return > end Scan; > ..................................................... > > I submit this in response to the observation someone made about the alleged > added > difficulty Ada imposes on the programmer in flexibility of expressiveness. In > my > own experience, Ada is far more expressive of a larger range of idioms than C++. > Note my use of the word "expressive." We can express any idea in any language, > but some languages are more expressive of some ideas than others. I think you mean something like: #include #include int main() { using namespace std; map id; id[-400]= 7.1; id[-2500]= -1; id[10]= 9; id[-300]= 7.1; unsigned counter= 0; for(map::const_iterator p= id.begin(); p!=id.end(); ++p) { if(p->second== 7.1) { cout<<"7.1 was found at index "<first<<"\n"; ++counter; } } cout<<"\n7.1 was found "<temp 7.1 was found at index -400 7.1 was found at index -300 7.1 was found 2 times in total. C:\c> I think this is even faster than yours, which scans the entire range. And a more elegant and with the same efficiency solution: #include #include #include class comp: public std::unary_function, bool> { const double searchValue; public: comp(const double value):searchValue(value) {} bool operator() (const std::pair &arg) const { if(arg.second==searchValue) return true; return false; } }; int main() { using namespace std; map id; id[-400]= 7.1; id[-2500]= -1; id[10]= 9; id[-300]= 7.1; cout<<"\n7.1 was found "<temp 7.1 was found 2 times in total. C:\c> > > 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 http://www23.brinkster.com/noicys