Topic: How to avoid implicit template instantiations
Author: Wil Evers <bouncer@dev.null>
Date: 2000/09/21 Raw View
Hi,
In an attempt to speed up to compile/link cycle of our largest
application, I stumbled across a trick that appears to work both with
egcs-1.1.2 and MSVC++ 6.0 sp4:
extern template std::vector<int>;
The line above prevents the implicit instantiation of std::vector<int>
from the current translation unit; it can be put into a header file
for a library of pre-instantiated templates. At least for compilers
that use the 'Borland model', this can result in a significantly faster
compile/link cycle.
I checked the standard, but I couldn't find any reference to this
construct, so I guess it is non-compliant.
If this is indeed a non-standard extension, I would like to avoid it.
Therefore: does the standard define any way to prevent a specific
implicit template instantiation?
All I can come up with is splitting up the header files defining
a template into separate interface and implementation headers, and only
including the interface part if I don't want implicit instantiations.
This is fine for home-grown templates, but not for headers over which
we have no control, like those defining the standard library.
Thanks,
- Wil
--
Wil Evers, DOOSYS IT Consultants, Maarssen, Holland
[Wil underscore Evers at doosys dot com]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: comeau@panix.com (Greg Comeau)
Date: 2000/09/21 Raw View
In article <mifcq8.c02.ln@tinus.intra.doosys.com>,
Wil Evers <bouncer@dev.null> wrote:
>In an attempt to speed up to compile/link cycle of our largest
>application, I stumbled across a trick that appears to work both with
>egcs-1.1.2 and MSVC++ 6.0 sp4:
>
> extern template std::vector<int>;
>
>The line above prevents the implicit instantiation of std::vector<int>
>from the current translation unit; it can be put into a header file
>for a library of pre-instantiated templates. At least for compilers
>that use the 'Borland model', this can result in a significantly faster
>compile/link cycle.
>
>I checked the standard, but I couldn't find any reference to this
>construct, so I guess it is non-compliant.
Right, it's not compliant. Furthermore, your delayed instantiation
is really just a side-effect of the extern extension (though as
you've found, it'll work).
>If this is indeed a non-standard extension, I would like to avoid it.
It is.
>Therefore: does the standard define any way to prevent a specific
>implicit template instantiation?
No, but you'll find 'export', although not compiler yet supports it.
>All I can come up with is splitting up the header files defining
>a template into separate interface and implementation headers, and only
>including the interface part if I don't want implicit instantiations.
>This is fine for home-grown templates,
Right.
>but not for headers over which
>we have no control, like those defining the standard library.
Gotta wait, or use some extension or another.
You can also exlicitly instantiation some templates in certain
places, and perhaps your compiler will recognize some other
object file "owns" the instantiation.
- Greg
--
Comeau Computing / Comeau C/C++ ("so close" 4.2.44 betas starting)
TRY Comeau C++ ONLINE at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]