Topic: ANSI compiant explicit template instantation


Author: bkeefe@seas.gwu.edu (Brian J. Keefe)
Date: 1995/12/06
Raw View
The online MSVC4 manual says to use syntax like:

template Stack<int,6>;

to force class template instantiation for all operations.
I did not find this in the ARM. Is it ANSI compliant?

Thanks,
-- Brian Keefe
bkeefe@manu.com






---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
Date: 1995/12/07
Raw View
In article <4a4io5$s0v@cronkite.seas.gwu.edu> bkeefe@seas.gwu.edu
(Brian J. Keefe) writes:

|> The online MSVC4 manual says to use syntax like:

|> template Stack<int,6>;

|> to force class template instantiation for all operations.
|> I did not find this in the ARM. Is it ANSI compliant?

No.  The standard offers no means of forcing template instantiation,
probably because forcing instantiation has no utility.

If you use the template, it is instantiated.  You don't need to force
instantiation.  If you don't use it, why do you want to instantiate
it?  Just to have extra code (which is never called) in your
application.

Note that in most modern implementations, if you use a template in a
library, the implementation will instantiate the template and include
the code of the instantiation in the library automatically.
(Historically, with older link-time instantiation compilers, like
CFront, you had to do this manually.  But while I was very happy to
have CFront back then, it is hardly what I would call state of the art
today.)

--
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils,    tudes et r   alisations en logiciel orient    objet --
                -- A la recherche d'une activit    dans une region francophone



---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: gnb@bby.com.au (Gregory Bond)
Date: 1995/12/08
Raw View
In article <9512071347.AA29456@lts.sel.alcatel.de> James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> writes:

   No.  The standard offers no means of forcing template instantiation,
   probably because forcing instantiation has no utility.

What about 14.4 (April DWP):

  14.4  Explicit instantiation                           [temp.explicit]

1 A class or function specialization can be explicitly instantiated from
  its template.

2 The syntax for explicit instantiation is:
          explicit-instantiation:
                  template declaration
  Where the unqualifier-id in the declaration shall  be  a  template-id.
  [Example:
          template class Array<char>;

          template void sort<char>(Array<char>&);
   --end example]

[etc]

Greg.
--
Gregory Bond <gnb@bby.com.au> Burdett Buckeridge & Young Ltd Melbourne Australia
``Efforts to maintain the "purity" of a language only succeed in establishing an
  elite class of people who know the shibboleths.  Ordinary folks know better,
  even if they don't know what "shibboleth" means.'' - Larry Wall

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]






Author: jesjones@halcyon.com (Jesse Jones)
Date: 1995/12/08
Raw View
In article <9512071347.AA29456@lts.sel.alcatel.de>, James Kanze US/ESC
60/3/141 #40763 <kanze@lts.sel.alcatel.de> wrote:

> In article <4a4io5$s0v@cronkite.seas.gwu.edu> bkeefe@seas.gwu.edu
> (Brian J. Keefe) writes:
>
> |> The online MSVC4 manual says to use syntax like:
>
> |> template Stack<int,6>;
>
> |> to force class template instantiation for all operations.
> |> I did not find this in the ARM. Is it ANSI compliant?
>
> No.  The standard offers no means of forcing template instantiation,
> probably because forcing instantiation has no utility.

 [snip]

 Section 14.4 of the draft standard documents explicit template
instantiation: the syntax is "template class Stack<int, 6>;". BTW I know
of two uses for explicit instantiation:

1) It forces every function defined in the template class to be
instantiated. This means that each function is actually compiled: you
don't have to worry about some stupid syntax error in functions that
haven't been used.

2) More importantly there are times when you want to control where the
code is generated. For example, programs that have to run on low end Macs
often segment the code so it doesn't all have to be in memory at once. In
this sort of situation it's very nice to be able to control where the
commonly used template classes go.

  --Jesse


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]