Monday November 06, 2006 Upcoming SunStudio Express 3 will include one more c++ language extension. Recently I have implemented explicit template definition aka forward declaration of explicit instantiations. Now this extension is available under -Qoption ccfe -features=gcc command line option.
In the code below compiler will not instantiate (explicitly and implicitly) any members of class S<int>. So it will not waste a time on code generation and optimization. The only source code file should contain explicit template instantiation to successfully link the program.
% cat test.h
template <typename T>
struct S
{
void foo();
};
template <typename T>
void S<T>::foo()
{
// a lot of code here
}
extern template struct S<int>;
% cat inst.cc #include "test.h" template struct S<int>;
% cat main.cc
#include "test.h"
int main()
{
S<int> s;
s.foo();
}