Template + member function pointers

Started by
3 comments, last by hogwash 18 years, 6 months ago
I have a problem working member function pointers into my template So I have this: template <class signature> class Foo; and this is good for static functions: template <class t0, class t1> class Foo <t0 (t1)> { ... } but I don't know how to work in member functions. I have tried the following template <class type, class t0, class t1> class Foo <t0 (type::)(t1)> { ... } but that doesn't work. Any ideas?
Advertisement
This isn't exactly the same as what you are trying to do, but it should help you out:

#ifndef MKH_META_FT_HPP#define MKH_META_FT_HPP#include "Loki/TypeList.h"namespace mkh{	namespace meta	{		template<typename R, typename T1 = void>		struct function_traits;		template<typename R>		struct function_traits<R (*)(void)>		{			static const int parameters = 0;			static const bool member = false;			typedef R (*Functor)(void);			typedef R Result;			typedef TYPELIST_1(void) Parameters;		};		template<typename R, typename T1>		struct function_traits<R (*)(T1 t1)>		{			static const int parameters = 1;			static const bool member = false;			typedef R (*Functor)(T1);			typedef R Result;			typedef TYPELIST_1(T1) Parameters;		};		template<typename R, typename T1, typename T2>		struct function_traits<R (*)(T1 t1, T2 t2)>		{			static const int parameters = 2;			static const bool member = false;			typedef R (*Functor)(T1,T2);			typedef R Result;			typedef TYPELIST_2(T1, T2) Parameters;		};		//Member Functions		template<typename R, class Cls>		struct function_traits<R (Cls::*)(void)>		{			static const int parameters = 0;			static const bool member = true;			typedef R (Cls::*Functor)(void);			typedef Cls Class;			typedef R Result;			typedef TYPELIST_1(void) Parameters;		};		template<typename R, class Cls, typename T1>		struct function_traits<R (Cls::*)(T1 t1)>		{			static const int parameters = 1;			static const bool member = true;			typedef R (Cls::*Functor)(T1);			typedef Cls Class;			typedef R Result;			typedef TYPELIST_1(T1) Parameters;		};		template<typename R, class Cls, typename T1, typename T2>		struct function_traits<R (Cls::*)(T1, T2)>		{			static const int parameters = 2;			static const bool member = true;			typedef R (Cls::*Functor)(T1, T2);			typedef Cls Class;			typedef R Result;			typedef TYPELIST_2(T1, T2) Parameters;		};	}//ns meta}//ns mkh#endif //MKH_META_FT_HPP
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I don't know for sure but by the looks of thing it looks like you could be using std::tr1/boost::function if your not but doing something similar (i.e variable number of template arguments + variable number of template (partial) specializations) i'd recommend using Boost.Preprocessor for all that boilerplate code like in Shannon's example.

Try typedef'ing the member function pointer datatype.
I love me and you love you.
Well you can't pass pointers in as template arguments anyway.

This topic is closed to new replies.

Advertisement