[Insight-developers] Explicit Instantiation Proposal

Brad King brad.king at kitware.com
Fri Apr 28 09:32:45 EDT 2006


Miller, James V (GE, Research) wrote:
> I want stress that I am in favor of explicit instantiation.  The improvements in build
> time and disk usage will be significant.  Of these two, disk usage is my primary 
> concern because I rarely have to build all of ITK.  Usually I am working in a small 
> sandbox that builds against ITK and my sandbox always builds very quickly.  However,
> I like to have several builds of ITK with different versions and different compilers.
> 
> I want the explicit instantiation mechansism to be something that we can support long
> term and be a model that we can propagate to projects that build against ITK.

If the only hang-up with the macro-based design is the form of the 
per-template macro, it should be possible to simplify them a bit.  For 
example, I can probably make them look like this:

#define ITK_TEMPLATE_Foo(_, EXPORT, x, y) \
   ITK_TEMPLATE_CLASS(_, EXPORT, Foo, 1, x, y)

#define ITK_TEMPLATE_Vector(_, EXPORT, x, y) \
   ITK_TEMPLATE_CLASS(_, EXPORT, Vector, 2, x, y) \
   namespace itk \
   { \
   _(1(EXPORT std::ostream& operator<<(std::ostream&, 
Templates::Vector##y&))) \
   _(1(EXPORT std::istream& operator>>(std::istream&, 
Templates::Vector##y&))) \
   }

...and the part outside ITK_TEMPLATE_CLASS will be needed only for a few 
templates.  The macro ITK_TEMPLATE_CLASS need be defined only once in 
itkMacro.h:

#define ITK_TEMPLATE_CLASS(_, EXPORT, c, n, x, y) namespace itk { \
   namespace Templates { typedef c < ITK_TEMPLATE_##n x > c##y; } \
   _(n(class EXPORT c < ITK_TEMPLATE_##n x >)) \
   }

> I do have one concern that may have been addressed when during the wrapping developements.
> At one time, we had some classes where we could not instantiate the entire class (all methods) for 
> every data type.  Some of the methods were appropriate for some data types and some methods
> were appropriate for other data types.  Do we still have this issue in ITK?

Possibly, and these classes will have problems with explicit 
instantiation.  It should be possible to do some template 
meta-programming to work-around the issues though.

-Brad


More information about the Insight-developers mailing list