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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,50fdde6c2a894ef1 X-Google-Attributes: gid103376,public From: Brian Rogoff Subject: Re: Difference between C++'s templates and Ada's generic units Date: 1998/01/26 Message-ID: #1/1 X-Deja-AN: 319392748 References: <6ai045$50p40@beaker.nit.gwu.edu> Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: 885829371 18121 bpr 206.184.139.132 Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-01-26T00:00:00+00:00 List-Id: 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