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();
}
Posted by DP on November 07, 2006 at 07:28 PM MSK #
Posted by Simon on November 09, 2006 at 04:21 PM MSK #
Posted by Ali on January 25, 2007 at 02:36 AM MSK #
To use "-Qoption ccfe -features=gcc" you need Sun C++ 5.9 (Sun Studio 12). You can download it here http://developers.sun.com/sunstudio/downloads/index.jsp. Also I recommend to install patch-01 for it. Please note this flag enables features which are not released yet. So use it on your own risk.
Posted by 194.8.176.164 on February 03, 2008 at 12:08 PM MSK #