Re: Partial Spezialization of member function

From: Rob Williscroft (rtw_at_freenet.co.uk)
Date: 09/30/04


Date: 30 Sep 2004 13:49:59 GMT

Paul Schneider wrote in news:cjh1j6$cni$1@trane.wu-wien.ac.at in
comp.lang.c++:

> I am getting compiler errors with the following setup

Standard C++ doesn't allow function's (member or not) to be partialy
specialized, you may however add overloads and you may have explicit
specialization's.

If neither of the above is of use to you, implement you function in
a helper class, and partialy specialize the helper:

/* Untested code, expect typo's */

struct X;

template < typename T >
struct helper
{
  static void apply( X *that )
  {
    // default body for X::f< T >() goes here
  }
};

struct X
{
  template < typename T > void f()
  {
    helper< T >::apply( this );
  }
};

/* Now *partialy* specialize
*/
#include <complex>

template < typename T >
struct helper< std::complex< T > >
{
  static void apply( X *that )
  {
    // body for X::f< std::complex< T > >() goes here
  }
};

HTH.

Rob.

-- 
http://www.victim-prime.dsl.pipex.com/


Relevant Pages