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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM 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!postnews.google.com!48g2000cwx.googlegroups.com!not-for-mail From: "Hyman Rosen" Newsgroups: comp.lang.ada Subject: Re: Ada generics Date: 22 Dec 2006 08:41:36 -0800 Organization: http://groups.google.com Message-ID: <1166805696.291429.239590@48g2000cwx.googlegroups.com> References: <1166710494.869393.108730@a3g2000cwd.googlegroups.com> <17fe4xfogg7p5.1dcyc5nyc2gsl.dlg@40tude.net> NNTP-Posting-Host: 204.253.248.208 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1166805702 7469 127.0.0.1 (22 Dec 2006 16:41:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 22 Dec 2006 16:41:42 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1; .NET CLR 2.0.50727) Gecko/20061204 Firefox/2.0.0.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: 48g2000cwx.googlegroups.com; posting-host=204.253.248.208; posting-account=lJDDWg0AAACmMd7wLM4osx8JUCDw_C_j Xref: g2news2.google.com comp.lang.ada:7991 Date: 2006-12-22T08:41:36-08:00 List-Id: 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. 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. > 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? > 6. Generic instance parameters. You can pass an instance as a parameter. C++ template parameters can themselves be template names. Is this something similar? > 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. > 9. Defaults for generic parameters C++ templates parameters can also have default values. However the lack of named association does mean that only a rightmost set can be elided. > 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.