Avoid typename repetition in template specialization

Frank Winter frank.winter@desy.de
Fri Apr 9 13:16:00 GMT 2010


Dear all,

suppose a templated class:

template< typename T >
struct A {
 	const T& some_function( const T& )
 	T i[10];
};

and a specialization for some type, say
PSpinVector< PColorVector< RComplex<REAL64>, Nc>, Ns >:

template<>
struct A<PSpinVector< PColorVector< RComplex<REAL64>, Nc>, Ns > > {
 	const PSpinVector< PColorVector< RComplex<REAL64>, Nc>, Ns >& 
some_function( const PSpinVector< PColorVector< RComplex<REAL64>, Nc>, Ns 
>& )
 	PSpinVector< PColorVector< RComplex<REAL64>, Nc>, Ns > i[10];
};

Is there a way to avoid the redundant typing of the specialized typename 
in the template specialization?

I know, using templates would exactly avoid this. But I really need 
this kind of specialization to specialize the some_function

I would not like to use the preprocessor. Like:

#define PSpinVector< PColorVector< RComplex<REAL64>, Nc>, Ns > T
template<>
struct A<T> {
 	public:
 	const T& some_function( const T& )
 	T i[10];
}
#undef T


Isn't there a template-way of doing this?


Best regards,
Frank Winter


--

Institut fuer theoretische Physik
Universitaet Regensburg
Universitaetsstr. 31
93053 Regensburg
Germany

office +49 (0)941 943 2085



More information about the Gcc-help mailing list