[Insight-developers] RE: itkStaticConstMacro and Explicit Instantiation

Miller, James V (Research) millerjv at crd.ge.com
Tue, 27 Apr 2004 09:36:09 -0400


Brad, 

I had to put an explicit instantiation of ParametricPath into the ITKCommon
dll a ways back. ParametricPath is a templated class that has non-templated
subclasses.  itkParametricPath ended up with a .h, a .txx and a .cxx file.

Would this work in place of "extern template"?

Otherwise, the StaticConstMacro is defined as unsigned int everywhere it
can because that was supposed to be the "accepted" practice.  At the time
we might have thought this would also help us support the compilers on 
Solaris but I am not sure whether we have recently is checked whether the 
Solaris compilers have caught up to ITK.

Jim



-----Original Message-----
From: Brad King [mailto:brad.king at kitware.com]
Sent: Monday, April 26, 2004 4:58 PM
To: Jim Miller
Cc: Insight Developers
Subject: itkStaticConstMacro and Explicit Instantiation


Jim,

I've been trying to introduce explicit instantiations in my working copy 
of ITK, but I've run into a problem with itkStaticConstMacro.  This 
example demonstrates the problem:

template <int N>
struct A
{
   static const unsigned int D = N;
   typedef A<D> Self;
};

extern template struct A<2>;

When compiling with GCC 3.3, the compiler is walking through the 
declarations of A<2> and marking them as do-not-instantiate.  When it 
gets to the typedef, it needs to access the definition of "D", but it is 
not allowed to instantiate D and complains.  If I replace the 
declaration of D with an enumeration, it works.

If I remember correctly, we need the StaticConstMacro only because 
Borland does not support using an enumeration.  Since Borland does not 
support extern template anyway, I propose that we change the macro to 
use enum everywhere but borland.

Comments?
-Brad