[Insight-developers] partial template specialization for functions

gang song songgang97 at gmail.com
Tue May 3 18:34:06 EDT 2011


Hi,

I want to check the partial template specialization alternative
solution for functions in ITK. One example is in
LinearInterpolateImageFunction.h, the function
EvaluateAtContinuousIndex() implemented "template specialization"
using function overloading as:


template< class TInputImage, class TCoordRep = double >
class ITK_EXPORT LinearInterpolateImageFunction:
  public InterpolateImageFunction< TInputImage, TCoordRep >
{
...
 virtual inline OutputType EvaluateAtContinuousIndex(const
                                                      ContinuousIndexType &
                                                      index) const
  {
    return this->EvaluateOptimized(Dispatch< ImageDimension >(), index);
  }


  struct DispatchBase {};
  template< unsigned int >
  struct Dispatch: DispatchBase {};

  inline OutputType EvaluateOptimized(const Dispatch< 0 > &,
                                      const ContinuousIndexType & index) const
  {
    return 0;
  }

  inline OutputType EvaluateOptimized(const Dispatch< 1 > &,
                                      const ContinuousIndexType & index) const
  {
   // something else ...
  }
}




Is this the canonical way to make the function partial specialization ?


Thanks

-Gang


More information about the Insight-developers mailing list