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,a84eaf8fb2470909 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!newsfeed01.chello.at!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ada generics 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: <1166710494.869393.108730@a3g2000cwd.googlegroups.com> <17fe4xfogg7p5.1dcyc5nyc2gsl.dlg@40tude.net> <1166805696.291429.239590@48g2000cwx.googlegroups.com> Date: Sat, 23 Dec 2006 12:43:51 +0100 Message-ID: NNTP-Posting-Date: 23 Dec 2006 12:43:36 CET NNTP-Posting-Host: 1276cc85.newsspool2.arcor-online.net X-Trace: DXC=58>g^@e=U`8Tia]Ho99G50A9EHlD;3Yc24Fo<]lROoR1Fl8W>\BH3Y2adIk@OHcEbl^FHlR`Cci>hX13bCUYbT: X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8003 Date: 2006-12-23T12:43:36+01:00 List-Id: On 22 Dec 2006 08:41:36 -0800, Hyman Rosen wrote: > Dmitry A. Kazakov wrote: >> 1. Contract-based (this is the most important feature) > > The C++ community is working on something called "concepts" which will > be a way for templates to specify constraints on the parameters. The > difficulty in C++ is the presence of automatic conversions and > different overloaded operators. For example, you may have a template > which uses "x < y" for the objects declared to be of type parameter T. > When instantiating, there could be many ways of compiling this > statement depending on the nature of the type parameter. It can be a > member function of T taking one or two parameters, it can be a global > function taking two T parameters, or it can be a function taking > parameters not of type T but of a type to which T can be converted > automatically. Similarly, the return type can be bool, or it can be a > numeric type, or some object type that can be automatically converted > to bool. Automatic type conversion is a fixed part of the C++ universe, > and templates have to live and work within that environment. Automatic conversions do not represent any special case. If S is convertible to T, then S is a subtype of T, in the sense that it inherits < from it. When S defines <, that is equivalent to overriding <. C++'s problem is in chaotic design. There is no need in a new concept of "concept," sorry for an unintended pun. That concept is called class = a set of types. > In any case, it's never been clear to me why constraints on generic > parameters are considered to be so important by some people. Why not > let templates be instantiated with anything the caller likes? In C++, > if the parameters fail to satisfy some requirement in the template, > then the compilation will fail. If the compilation succeeds, then you > have a working instantiation. It's more likely that a constraint will > prevent an unforeseen but valid usage from working than that it will > catch some kind of error. There is an even better way. It could be called "genetic programming." Let the template generate an arbitrary code. If it compiles, it goes into production. Customers give a feedback...(:-)) >> 3. Generic object parameters can have any type (in C++ you cannot use >> float, for example) > > Just a note on the float constraint. C++ considers instantiations > identical if their parameters are identical, and introducing floating > point can lead to ambiguities that the language designers chose to > avoid by fiat. It's just the usual floating point issues, e.g., is > 1.0/3.0*3.0 the same as 1.0? On which platforms? Exactly. The idea of structural matching is wrong. It is uncheckable. So what language designers do? Ada designers drop the idea and go typed. C++ designers chaotically drop some cases and some checks in an attempt to save something that cannot be. [ BTW, I am unhappy with anonymous access types introduced in Ada 95. It was the C++ way. ] >> 6. Generic instance parameters. You can pass an instance as a parameter. > > C++ template parameters can themselves be template names. Is this > something similar? Yes, I think so. >> 7. Generic packages (~namespaces). Anything you put in gets parametrized by >> the formal parameters and instantiated upon the package instantiation. > > In C++, classes serve the same purpose as do Ada packages, so this is > not really a difference. It is actually the difference between packages in Ada and classes in C++. They are not equivalent. >> 10. Nested generics and generic children > > C++ class templates can have further class templates declared inside > them, and class templates can inherit from other classes, so I don't > see a difference here. I think that 10 and 7 are in fact the same question, and any difference is not specific to generics/templates. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de