[Insight-developers] Explicit Instantiation Proposal
Brad King
brad.king at kitware.com
Wed Apr 26 08:46:22 EDT 2006
Kris Thielemans wrote:
> I'm just wondering if this isn't a lot of effort that will become obsolete
> once the 'export' keyword is more widely available. In any case, you should
> make sure that the macros are export-compatible. See also (very briefly)
> http://www.parashift.com/c++-faq-lite/templates.html#faq-35.14
There are three parts to this answer:
1.) The export keyword may never be widely available. It is so hard to
implement that there is talk of removing it from the C++ standard. Even
if it does we will not be dropping support for most of the current
non-export compilers for a long time.
2.) The export keyword does not obsolete this design. Having
pre-compiled fully instantiated copies of the common template
instantiations will still be faster/smaller than using export. All the
export keword does is allow "separate compilation of templates". In
practice this amounts to putting a parse tree in an object file and then
using it during linking to produce the needed symbols. This would still
require the compiler to build these instantiations for user code. The
pre-link step used to build the exported templates is hard to
parallelize too.
3.) The design is export-compatible because explicit instantiations have
almost nothing to do with export. If we later add the .txx files into
the build on an export-supporting compiler it will simply allow the
non-explicitly-instantiated templates to take advantage of export. As
will be seen when I write the section on organizing source files, all
the .h files include their .txx files optionally inside a #if test which
is easy to modify later to be false when export is enabled.
-Brad
More information about the Insight-developers
mailing list