[Insight-developers] partial template specialization for functions

Gaëtan Lehmann gaetan.lehmann at jouy.inra.fr
Wed May 4 15:16:24 EDT 2011


Le 4 mai 11 à 00:34, gang song a écrit :

> 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 ?


Hi,

This is one way to do that.
For an example of another way, without using a dispatch class, you can  
look at

   PerimeterFromInterceptCount

in

   Modules/Nonunit/Review/include/itkShapeLabelMapFilter.h

Regards,

Gaëtan


-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr  http://www.itk.org
http://www.mandriva.org  http://www.bepo.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: Ceci est une signature ?lectronique PGP
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20110504/c7d68d38/attachment.pgp>


More information about the Insight-developers mailing list