From: Brian Rogoff <bpr@shell5.ba.best.com>
Subject: Re: Difference between C++'s templates and Ada's generic units
Date: 1998/01/26
Date: 1998-01-26T00:00:00+00:00 [thread overview]
Message-ID: <Pine.BSF.3.96.980126072230.19956A-100000@shell5.ba.best.com> (raw)
In-Reply-To: 6ai045$50p40@beaker.nit.gwu.edu
On 26 Jan 1998, Samir N. Muhammad wrote:
> Hello everybody,
>
> Would someone explain whether there is a difference between C++'s templates
> and Ada's generic units. I checked the WEB document by David Wheeler,
> "Ada,C,C++, and Java vs. The Steelman", and found out that the only difference
> is that C++'s templates are not yet standardized. Are there any essential
> differenes between C++ and Ada support for generic programming.
>
>
>
>
> Thanks in advance
> Samir Muhammad
Hi Samir,
There are numerous differences between the two. As I haven't
used C++ templates for a while, I can't comment on many of the changes
that occurred recently, so check your ISO draft document. Some of the
most important differences to me are
(1) C++ supports only unconstrained genericity (no constraints on generic
parameters), Ada supports both constrained and unconstrained
genericity. You can fake constraints in C++, but its very ugly.
(2) C++ does some automatic instantiation of templated functions, all
Ada instantiation is explicit. Indeed, C++ can do arbitrary
computations during template expansion, the so called "template
metaprogramming". I like the first, and wish Ada allowed some
automatic instantiation of generics, but feel the other stuff beyond
that is too much like macros.
(3) Ada generic units can be separately compiled and are type checked at
compile time.
(4) Ada's null bodied generic package specs and sharing constraints on
formal package parameters allow an "ML-like" programming style.
Barnes' book and the Ada 95 Rationale have some nice examples.
(5) Functions and procedures can be used as generic parameters in Ada.
You'd have to fake this by wrapping your function in a class in C++.
....
There are lots more, but these should be enough to convince you that the
differences go beyond the issue of standardization alone! In fact, C++ is
almost a standard, so these documents should soon be revised.
-- Brian
next prev parent reply other threads:[~1998-01-26 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-01-26 0:00 Difference between C++'s templates and Ada's generic units Samir N. Muhammad
1998-01-26 0:00 ` Brian Rogoff [this message]
1998-01-26 0:00 ` Steve Doiel
-- strict thread matches above, loose matches on Subject: below --
1998-01-26 0:00 Samir N. Muhammad
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox