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,243dc2fb696a49cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!newsfeed.pionier.net.pl!news.nask.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail From: "Robert Kawulak" Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) Date: Sun, 3 Oct 2004 21:53:32 +0200 Organization: tp.internet - http://www.tpi.pl/ Message-ID: References: <41547dae$0$91007$39cecf19@news.twtelecom.net> <1g2d9xmnita9f.5ecju0eftkqw$.dlg@40tude.net> <1hl2mizeb27ku$.1f0asrbmb05mi.dlg@40tude.net> <7siml3c62lev$.usczt2y2l19c$.dlg@40tude.net> <15fk5715wm38q.3ie9r3bq8yuz$.dlg@40tude.net> NNTP-Posting-Host: pc100.krakow.cvx.ppp.tpnet.pl X-Trace: nemesis.news.tpi.pl 1096833923 7641 213.76.38.100 (3 Oct 2004 20:05:23 GMT) X-Complaints-To: usenet@tpi.pl NNTP-Posting-Date: Sun, 3 Oct 2004 20:05:23 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Xref: g2news1.google.com comp.lang.ada:4626 Date: 2004-10-03T21:53:32+02:00 List-Id: Hi, > In Ada slices are ad-hoc anonymous types, it is how that should be. > Because > if you want to work with array slices in a subprogram, you definitely do > not want to pass all necessary helper types down there. In Ada you just > write A(10..I) and the job is done. In C++ you may write std::vector(V.begin + 9, V.begin() + I) and this is also anonymous object which is subvector of another vector V. Or you can pass only iterators and the job is done better, because there's no copying of elements and you can operate on any container, not only on a vector. > [Yes you can get this in C++, I believe you, it is all Turing complete > after all! (:-))] :))) >> std::for_each algorithm and the like... (especially useful with >> boost::lambda) > > In Ada: > > for Index in A'Range loop > ... > end loop; > > Here the iterator type and its constraint are constructed out of the > object. Feel the difference! The only case where Ada is less verbose than C++ ;-) But on the other hand you cannot do this with a list, a map, a deque, nor you can do the following so concisely: std::vector V(10); // Apply SomeFunction to elements [4, 9] in reverse order: std::for_each(V.rbegin() + 1, V.rend() - 3, SomeFunction); For instance (using boost::lambda) print those elements: // Print elements [4, 9] in reverse order: std::for_each(V.rbegin() + 1, V.rend() - 3, std::cout << _1); Feel the difference! ;-) >> I see your point. When designing containers in std library, its creators >> had >> two possibilities to choose from: >> 1. Make all the containers polymorphic, >> 2. Make all the containers use consequent naming of members and make all >> the >> algorithms templated. >> They have choosen 2, because it's far more efficient (no virtual calls, >> many >> bindings resolved at compile time and even inlined) and far more >> flexible. > > Far less flexible you mean. C++ doesn't have a single-rooted object hierarchy. So if containers weren't templates, they'd have to contain elements of some abstract class, call it CElement. Now, if you want to have a container of elements of some class not derived from CElement or even a container of int, then you'd have to make some wrapper classes - this would cost you a lot of time to make it work with the library. So in this case runtime polymorphism doesn't seem to me to be more flexible than the template solution... > No you cannot, when you have to mix them. If your program needs both > vector and string (to copy a part of one into another) then you have > to parametrize it twice with two types. Now consider what happens if there > are 100 different, yet related types? Nothing happens. ;-) If you have a function template copying elements of one container into another, then it'll work fine even for 100 container types, as long as they use the same interface. Can you specify what do you mean when saying 'mix them'? > [To continue the analogy, I'am trying to convince a FORTRAN-IV programmer > that there could be something beyond REAL*4 and REAL*8. (:-))] I feel the same ;-). But of course the point is not to fight and win, but to learn something. I've already learned a few things from this discussion :). Best regards, Robert