comp.lang.ada
 help / color / mirror / Atom feed
From: "Hyman Rosen" <hyman.rosen@gmail.com>
Subject: Re: Ada generics
Date: 22 Dec 2006 08:41:36 -0800
Date: 2006-12-22T08:41:36-08:00	[thread overview]
Message-ID: <1166805696.291429.239590@48g2000cwx.googlegroups.com> (raw)
In-Reply-To: 17fe4xfogg7p5.1dcyc5nyc2gsl.dlg@40tude.net

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.




  parent reply	other threads:[~2006-12-22 16:41 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-21 14:14 Ada generics markww
2006-12-21 15:42 ` Dmitry A. Kazakov
2006-12-22  7:59   ` Martin Krischik
2006-12-22 16:14     ` Hyman Rosen
2006-12-22  7:59   ` Martin Krischik
2006-12-22 16:41   ` Hyman Rosen [this message]
2006-12-22 17:33     ` Markus E Leypold
2006-12-22 18:26       ` Hyman Rosen
2006-12-22 20:59         ` Markus E Leypold
2006-12-22 21:01           ` Markus E Leypold
2006-12-23 14:09           ` Marco
2006-12-25 14:23             ` Hyman Rosen
2006-12-29 14:13               ` Marco
2006-12-25 14:20           ` Hyman Rosen
2006-12-23 11:43     ` Dmitry A. Kazakov
2006-12-25 13:49       ` Hyman Rosen
2006-12-25 14:39         ` Dmitry A. Kazakov
2006-12-26  1:34           ` Hyman Rosen
2006-12-26  9:11             ` Dmitry A. Kazakov
2006-12-26 16:23               ` Hyman Rosen
2006-12-26 19:28                 ` Dmitry A. Kazakov
2006-12-27  1:44                   ` Hyman Rosen
2006-12-27  9:21                     ` Dmitry A. Kazakov
2006-12-27 19:06                       ` Hyman Rosen
2006-12-28 10:59                         ` Dmitry A. Kazakov
2006-12-28 16:29                           ` Hyman Rosen
2006-12-29 11:12                             ` Dmitry A. Kazakov
2006-12-29 14:56                               ` Hyman Rosen
2006-12-28 17:35                           ` Georg Bauhaus
2006-12-29 14:48                             ` Dmitry A. Kazakov
2006-12-29 19:39                               ` Georg Bauhaus
2006-12-30  9:58                                 ` Dmitry A. Kazakov
2006-12-30 14:53                                   ` Georg Bauhaus
2007-01-01 13:00                                     ` Dmitry A. Kazakov
2007-01-02 10:04                                       ` Georg Bauhaus
2007-01-02 11:11                                         ` Dmitry A. Kazakov
2007-01-02 12:33                                           ` Georg Bauhaus
2007-01-02 13:51                                             ` Dmitry A. Kazakov
2007-01-02 14:45                                               ` Georg Bauhaus
2007-01-03 10:10                                                 ` Dmitry A. Kazakov
2007-01-03 14:20                                                   ` Hyman Rosen
2007-01-03 14:55                                                   ` Georg Bauhaus
2007-01-04 10:15                                                     ` Dmitry A. Kazakov
2007-01-03 19:33                                           ` Alexander E. Kopilovich
2007-01-04 10:27                                             ` Dmitry A. Kazakov
2007-01-04 15:00                                               ` Alexander E. Kopilovich
2007-01-05 10:32                                                 ` Dmitry A. Kazakov
2006-12-30  2:25                               ` Randy Brukardt
2006-12-30 10:13                                 ` Dmitry A. Kazakov
2007-01-04  1:09                                   ` Randy Brukardt
2007-01-04 10:07                                     ` Dmitry A. Kazakov
2007-01-05  1:32                                       ` Randy Brukardt
2007-01-05  4:46                                         ` Randy Brukardt
2007-01-05  9:08                                         ` Jean-Pierre Rosen
2007-01-05 20:14                                         ` Georg Bauhaus
2007-01-06  0:14                                           ` Randy Brukardt
2006-12-29  0:09                           ` Randy Brukardt
2006-12-29 11:11                             ` Dmitry A. Kazakov
2006-12-30  2:40                               ` Randy Brukardt
2006-12-21 16:55 ` Hyman Rosen
2006-12-21 18:22   ` markww
2006-12-22  3:01 ` Steve
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox