Re: Templates in C++

norman@flaubert.bellcore.com (Norman Ramsey)
Sun, 14 May 1995 19:59:29 GMT

          From comp.compilers

Related articles
Templates in C++ jcohen@juniper.tc.cornell.edu (1995-05-11)
Re: Templates in C++ litsios@iis.ee.ethz.ch (1995-05-12)
Re: Templates in C++ jsgray@ix.netcom.com (1995-05-12)
Re: Templates in C++ shepherd@schubert.sbi.com (1995-05-12)
Re: Templates in C++ norman@flaubert.bellcore.com (1995-05-14)
Re: Templates in C++ davidm@flora.Rational.com (1995-05-16)
Re: Templates in C++ jgmorris@cs.cmu.edu (Greg Morrisett) (1995-05-17)
Re: Templates in C++ jplevyak@violet-femmes.cs.uiuc.edu (1995-05-17)
Re: Templates in C++ bill@amber.ssd.hcsc.com (1995-05-25)
Re: Templates in C++ kanze@gabi-soft.fr (1995-05-29)
Re: Templates in C++ mac@coos.dartmouth.edu (1995-06-23)
[3 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: norman@flaubert.bellcore.com (Norman Ramsey)
Keywords: C++, performance
Organization: Bellcore, Morristown NJ
References: 95-05-081 95-05-096
Date: Sun, 14 May 1995 19:59:29 GMT

Marc Shepherd <shepherd@schubert.sbi.com> wrote:
>The other challenge with templates is the "code bloat" that can
>result if many very similar templates are instantiated. (I guess you
>could call this "performance related," in that it can lead to
>larger-than-normal executables.)
>
>In the pre-template days, if you wanted a general linked list class,
>you crated a list of generic pointers, and anyone using the class had
>to cast their objects to and from void*. (At least, this was one
>common way of doing it.) This required lots of unsafe casting, but
>only one copy of the list management code was generated.


I can't resist pointing out that one of the joys of programming in
Standard ML is that you can get this kind of polymorphism without any
unsafe casting and without replicating code. It works because the ML
type system is powerful enough that you can write functions to operate
on values of type 'a list (pronounced ``alpha list''), which stands
for any list type. A single instance of each function suffices for
all possible list types, and the proper use of these functions is
checked statically.


Jeff Ullman's ``Elements of ML Programming'' is ideal for C or C++
programmers who would like to learn more about ML.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.