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,243dc2fb696a49cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) Date: Wed, 29 Sep 2004 14:19:23 +0200 Message-ID: <6zobtdp3ckqx.plmvz5og15id.dlg@40tude.net> References: <41547dae$0$91007$39cecf19@news.twtelecom.net> <1g2d9xmnita9f.5ecju0eftkqw$.dlg@40tude.net> <87u4rkhddelw$.1uuoqhfyd2eay$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 495K+IxcwnL9hEQgZdPs9QamKNzBpsv/e7fusAntqd0zemQEM= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:4377 Date: 2004-09-29T14:19:23+02:00 List-Id: On Wed, 29 Sep 2004 01:26:39 +0200, Robert Kawulak wrote: >> First, that all will be templates, I do not want them, generics are >> inherently bad. For instance, it is impossible to have generic programming >> on containers of containers. You cannot have a list of items of "array" >> types that are different instantiations. > > I don't know about Ada, but in C++ you can, and such "templates nesting" > is even the recommended way to have multi-dimensional vectors: > > typedef vector< vector < vector > > vector_int_3D; It is another thing. What I meant is that you cannot have a vector containing elements of vector, vector, vector etc. vector and vector are unrelated types even if A is a descendant of B or related to B. What do you want from a macro extension? (:-)) >> Secondly it is not checked whether the thing you are implementing *is* an >> array which *will* work with all that standard algorithms. You never know >> before you instantiate. >> Ideologically, it is stone age, not the Ada's way, >> IMO. > > C++ templates are not checked only when instantiated. Every template > body is parsed, whether it's instantiated anywhere or not (this is why there > is the typename keyword). > That's as to grammar correctness. And if you mean semantics, I don't > thing Ada compiler will check them for you as well... You also have to write > some program using generic instantiations to test whether they work as you > expect them to do. No, Ada generics have contracts. It means that when you write: generic type X is private; procedure Foo (Object : in out X); it is not same as template void Foo (X& Object); because then you cannot refer Baz defined on X in Foo. Baz is not in the contract. So you need not to write any test, the Foo will not compile. You have to add Baz to the contract: generic type X is private; with procedure Baz (Object : in out X); procedure Foo (Object : in out X); Similarly with arrays: generic type Index is ... type Element is ... type Vector is array (Index range <>) of Element; procedure Foo (Container : in out Vector); Vector here is an array not because it has ()-operation, but because it conforms to the array interface. When you write an implementation of Foo you can rely on this and only this, nothing else. It is far away from C++ ideology of templates. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de