Jump to content
  • Advertisement
Sign in to follow this  
Axiverse

Template + member function pointers

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!