[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OFF-TOPIC] C++ template question



On Fri, 31 Oct 1997, Shaleh wrote:

> How is the STL shipped then.  We do not have access to its code do we??
> 

First off, since it's an official part of Debian, yes, we must have access
to the code somehow.

But aside from that, yes, _any_ template library that someone provides for
developers to use must be provided in source code form.  The standard
templates shipped with MSVC/C++ are all shipped in source code form.

The best way I've found to think of templates is as compiler macros.  (no,
I didn't say pre-processor macros, I said compiler macros - this means
that templates are more intelligent than preprocessor expansions).  They
don't actually generate any code until they are invoked; this is because
the code they could generate can't really be determined ahead of time -
how is the compiler going to know ahead of time whether 'a + b' occuring
in a piece of template code will eventually refer to one of the builtin
meanings of addition, or to a function of the form
type type::operator+(type arg)
or a function of the form
type operator+(type a, type b)
?  The short answer is that the compiler can't know - C++ allows so
many results from similar-looking code that the compiler just can't
compile templates by themselves.  However, once a template is
instantiated, then the compiler can go ahead and determine the basics of
what the code means.

This is why splitting templates into header and .c files doesn't make much
sense, any more than it would make sense to try to pre-compile
preprocessor macros.  (This is just one of the reasons why I find
templates nasty to work with, and really prefer to work in a language that
is completely object-oriented - the use of templates always seems
ridiculously arcane to me)


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: