public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Avoid typename repetition in template specialization
@ 2010-04-09 13:16 Frank Winter
  2010-04-09 13:42 ` Axel Freyn
  0 siblings, 1 reply; 5+ messages in thread
From: Frank Winter @ 2010-04-09 13:16 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: Avoid typename repetition in template specialization
@ 2010-04-09 13:57 Frank Winter
  2010-04-09 14:11 ` John (Eljay) Love-Jensen
  0 siblings, 1 reply; 5+ messages in thread
From: Frank Winter @ 2010-04-09 13:57 UTC (permalink / raw)
  To: gcc-help

Dear all,

Thanks John and Axel!

But, as I have a lot of these constructs typedef is exactly the problem:

   typedef PScalar< PColorMatrix< RComplex<REAL64>, Nc> > T1;
   typedef PSpinVector< PColorVector< RComplex<REAL64>, Nc>, Ns > T2;
   typedef OpMultiply Op;
   template<>
   inline BinaryReturn< T1 , T2 , Op >::Type_t
   operator*(const T1& l, const T2& r )
   {
     BinaryReturn< T1 , T2 , Op >::Type_t d;
     // code
     return d;
   }

now, this conflicts:

   typedef PSpinVector< PColorVector< RComplex<REAL64>, Nc>, Ns > T1;
   typedef PSpinVector< PColorVector< RComplex<REAL64>, Nc>, Ns > T2;
   typedef OpMultiply Op;
   template<>
   inline BinaryReturn< T1 , T2 , Op >::Type_t
   operator+(const T1& l, const T2& r )
   {
     BinaryReturn< T1 , T2 , Op >::Type_t d;
 	// code
     return d;
   }

If there would be a way to undefine a typename in the actual namespace 
this would help a lot in this case. Is there functionality for this or is 
there a workaround for my case that occurs to you?

Best regards,
Frank Winter


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-04-10 12:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-09 13:16 Avoid typename repetition in template specialization Frank Winter
2010-04-09 13:42 ` Axel Freyn
2010-04-09 13:57 Frank Winter
2010-04-09 14:11 ` John (Eljay) Love-Jensen
2010-04-10 12:51   ` Axel Freyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).