C++类型萃取编写技巧


C++类型萃取编写技巧,废话不多说,上来贴代码最实在,以下代码量有点多,不过这都是在下一手一手敲出来的,小巧好用,把以下代码复制出来,放到相应的hpp文件即可,VS,GCC下均能编译通过

#include<iostream>
#include "../../traits/traits.hpp"


using namespace std;


int show(char i, int j)
{
    return 1;
}

struct Stu
{
    int show(char i, int j)
    {
        return 1;
    }
};

int main()
{
    // 变量;类型萃取
    traits::type_traits<int>::const_value_type i = 5; // 通过traits::type_traits可以萃取到int类型的各种"衍生"类型,如指针什么的

    // 以下是C函数的相关萃取
    traits::function_traits<int(char, int)>::FunctionP_Type func_ptr = show; // 得到指针
    func_ptr('a', 4);

    cout << traits::function_traits<int(char, int)>::arity << endl; // 萃取出参数个数
    cout << typeid(traits::function_traits<int(char, int)>::arg2).name() << endl;//萃取出参数1的类型
    cout << typeid(traits::function_traits<int(char, int)>::arg1).name() << endl;//萃取出参数2的类型

    // 以下是类成员函数的相关萃取
    traits::mfunction_traits<int(Stu::*)(char, int)>::MFunctionP_Type mfunc_ptr = &Stu::show; // 得到指针
    Stu stu;
    ((&stu)->*mfunc_ptr)('a', 4);

    cout << typeid(traits::mfunction_traits<int(Stu::*)(char, int)>::arg2).name() << endl;//萃取出参数1的类型
    cout << typeid(traits::mfunction_traits<int(Stu::*)(char, int)>::arg1).name() << endl;//萃取出参数2的类型
    cout << typeid(traits::mfunction_traits<int(Stu::*)(char, int)>::result_type).name() << endl;//萃取出返回值
    cout << typeid(traits::mfunction_traits<int(Stu::*)(char, int)>::class_type).name() << endl;//萃取出类类型
   
    // 以下展示从C函数指针转为类成员函数指针的技巧
    traits::fun_to_mem_converter<int(char, int), Stu>::MFunctionP_Type mfunc_ptr2 = mfunc_ptr;
   
    // 以下展示从类成员函数指针转为C函数指针的技巧
    traits::mem_to_fun_converter<int(Stu::*)(char, int)>::FunctionP_Type func_ptr2 = func_ptr;
    return 0;
}

接下来是traits库的完整代码


########################
// traits.hpp

#ifndef TRAITS_INCLUDE
#define TRAITS_INCLUDE

#include "function_traits.hpp"
#include "mfunction_traits.hpp"
#include "fun_to_mem_converter.hpp"
#include "mem_to_fun_converter.hpp"
#include "type_traits.hpp"
#include "pointer_integer_traits.hpp"

#endif

########################

 


########################
// traits_config.hpp
#ifndef TRAITS_CONFIG_INCLUDE
#define TRAITS_CONFIG_INCLUDE

#define NAMESPACE_TRAITS_BEGIN namespace traits{
#define NAMESPACE_TRAITS_END }

#endif

########################

 


########################
//type_traits.hpp

#ifndef TYPE_TRAITS_INCLUDE
#define TYPE_TRAITS_INCLUDE

#include "traits_config.hpp"

NAMESPACE_TRAITS_BEGIN

template<typename T>
struct type_traits
{
    typedef T        value_type;
    typedef const T  const_value_type;
    typedef T*        pointer_type;
    typedef const T*  const_pointer_type;
    typedef T**      pointer_pointer_type;
    typedef const T** const_pointer_pointer_type;
    typedef T&        reference_type;
    typedef const T&  const_reference_type;
    typedef T*&      pointer_reference_type;
    typedef const T*& const_pointer_reference_type;

    static bool is_reference(){return false;};
    static bool is_pointer(){return false;};
    static bool is_value(){return true;};
    static bool is_pointer_reference(){return false;}
    static bool is_pointer_pointer(){return false;}

    static bool is_const_reference(){return false;};
    static bool is_const_pointer(){return false;};
    static bool is_const_value(){return false;};
    static bool is_const_pointer_reference(){return false;}
    static bool is_const_pointer_pointer(){return false;}
};

template<typename T>
struct type_traits<const T> : public type_traits<T>
{
    static bool is_const_reference(){return false;};
    static bool is_const_pointer(){return false;};
    static bool is_const_value(){return true;};
    static bool is_const_pointer_reference(){return false;}
    static bool is_const_pointer_pointer(){return false;}
};

template<typename T>
struct type_traits<T*>: public type_traits<T>
{
    static bool is_reference(){return false;}
    static bool is_pointer(){return true;}
    static bool is_value(){return false;}
    static bool is_pointer_reference(){return false;}
    static bool is_pointer_pointer(){return false;}
};

template<typename T>
struct type_traits<const T*>: public type_traits<T*>
{
    static bool is_const_reference(){return false;};
    static bool is_const_pointer(){return true;};
    static bool is_const_value(){return false;};
    static bool is_const_pointer_reference(){return false;}
    static bool is_const_pointer_pointer(){return false;}
};

template<typename T>
struct type_traits<T&>: public type_traits<T>
{
    static bool is_reference(){return true;}
    static bool is_pointer(){return false;}
    static bool is_value(){return false;}
    static bool is_pointer_reference(){return false;}
    static bool is_pointer_pointer(){return false;}
};

template<typename T>
struct type_traits<const T&>: public type_traits<T&>
{
    static bool is_const_reference(){return true;};
    static bool is_const_pointer(){return false;};
    static bool is_const_value(){return false;};
    static bool is_const_pointer_reference(){return false;}
    static bool is_const_pointer_pointer(){return false;}
};

template<typename T>
struct type_traits<T**>: public type_traits<T>
{
    static bool is_reference(){return false;}
    static bool is_pointer(){return false;}
    static bool is_value(){return false;}
    static bool is_pointer_reference(){return false;}
    static bool is_pointer_pointer(){return true;}
};

template<typename T>
struct type_traits<const T**>: public type_traits<T**>
{
    static bool is_const_reference(){return false;};
    static bool is_const_pointer(){return false;};
    static bool is_const_value(){return false;};
    static bool is_const_pointer_reference(){return false;}
    static bool is_const_pointer_pointer(){return true;}
};

template<typename T>
struct type_traits<T*&>: public type_traits<T>
{
    static bool is_reference(){return false;}
    static bool is_pointer(){return false;}
    static bool is_value(){return false;}
    static bool is_pointer_reference(){return true;}
    static bool is_pointer_pointer(){return false;}
};

template<typename T>
struct type_traits<const T*&>: public type_traits<T*&>
{
    static bool is_const_reference(){return false;};
    static bool is_const_pointer(){return false;};
    static bool is_const_value(){return false;};
    static bool is_const_pointer_reference(){return true;}
    static bool is_const_pointer_pointer(){return false;}
};


template<typename T>
struct type_expand_traits
{
    typedef T value_type;
    typedef T& reference_type;
    typedef T* pointer_type;
    typedef const T const_value_type;
    typedef const T& const_reference_type;
    typedef const T* const_pointer_type;
};

template<typename T>
struct type_expand_traits<const T>
{
    typedef T value_type;
    typedef T& reference_type;
    typedef T* pointer_type;
    typedef const T const_value_type;
    typedef const T& const_reference_type;
    typedef const T* const_pointer_type;
};

template<typename T>
struct type_expand_traits<T*>
{
    typedef T* value_type;
    typedef T*& reference_type;
    typedef T** pointer_type;
    typedef const T* const_value_type;
    typedef const T*& const_reference_type;
    typedef const T** const_pointer_type;
};

template<typename T>
struct type_expand_traits<const T*>
{
    typedef T* value_type;
    typedef T*& reference_type;
    typedef T** pointer_type;
    typedef const T* const_value_type;
    typedef const T*& const_reference_type;
    typedef const T** const_pointer_type;
};

template<typename T>
struct type_expand_traits<T**>
{
    typedef T** value_type;
    typedef const T** const_value_type;
};

template<typename T>
struct type_expand_traits<const T**>
{
    typedef T** value_type;
    typedef const T** const_value_type;
};

template<typename T>
struct type_expand_traits<T&>
{
    typedef T value_type;
    typedef T& reference_type;
    typedef T* pointer_type;
    typedef const T const_value_type;
    typedef const T& const_reference_type;
    typedef const T* const_pointer_type;
};

template<typename T>
struct type_expand_traits<const T&>
{
    typedef T value_type;
    typedef T& reference_type;
    typedef T* pointer_type;
    typedef const T const_value_type;
    typedef const T& const_reference_type;
    typedef const T* const_pointer_type;
};

template<typename T>
struct type_expand_traits<T*&>
{
    typedef T* value_type;
    typedef T*& reference_type;
    typedef T** pointer_type;
    typedef const T* const_value_type;
    typedef const T*& const_reference_type;
    typedef const T** const_pointer_type;
};

template<typename T>
struct type_expand_traits<const T*&>
{
    typedef T* value_type;
    typedef T*& reference_type;
    typedef T** pointer_type;
    typedef const T* const_value_type;
    typedef const T*& const_reference_type;
    typedef const T** const_pointer_type;
};

 

NAMESPACE_TRAITS_END
#endif

########################

 


########################
//pointer_integer_traits.hpp

/*
函数地址与整数之间的转换
*/
#ifndef POINTER_INTEGER_TRAITS_INCLUDE
#define POINTER_INTEGER_TRAITS_INCLUDE

#include "traits_config.hpp"

NAMESPACE_TRAITS_BEGIN

// 指针与整数的转换
template<typename funp>
struct _pointer_integer_traits
{
protected:
    funp _fun;
    _pointer_integer_traits(unsigned int addr)
    {
        union
        {
            funp _fun;
            unsigned int _addr;
        }_u;
        _u._addr = addr;
        _fun = _u._fun;
    }
public:
    operator funp()
    {
        return _fun;
    }
};


template<>
struct _pointer_integer_traits<unsigned int>
{
protected:
    unsigned int _addr;
    template<typename funp>
    _pointer_integer_traits(funp fun)
    {
        union
        {
            funp _fun;
            unsigned int _addr;
        }_u;
        _u._fun = fun;
        _addr = _u._addr;
    }
public:
    operator unsigned int()
    {
        return _addr;
    }
};

template<typename funp>
struct pointer_integer_traits : public _pointer_integer_traits<funp>
{
    pointer_integer_traits(const unsigned int addr):_pointer_integer_traits<funp>(addr){}
};

template<typename funp>
struct pointer_integer_traits<const funp*> : public _pointer_integer_traits<funp>
{
    pointer_integer_traits(const unsigned int addr):_pointer_integer_traits<funp>(addr){}
};

template<>
struct pointer_integer_traits<int> : public _pointer_integer_traits<unsigned int>
{
    template<typename funp>
    pointer_integer_traits(funp fun):_pointer_integer_traits<unsigned int>(fun){}

    template<typename funp>
    pointer_integer_traits(const funp* fun):_pointer_integer_traits<unsigned int>(fun){}
};


template<>
struct pointer_integer_traits<unsigned int> : public _pointer_integer_traits<unsigned int>
{
    template<typename funp>
    pointer_integer_traits(funp fun):_pointer_integer_traits<unsigned int>(fun){}

    template<typename funp>
    pointer_integer_traits(const funp* fun):_pointer_integer_traits<unsigned int>(fun){}
};

 

//////////////////////////////////////////

// 指针与引用的换
template<typename T>
struct pointer_reference_traits;

template<typename T>
struct pointer_reference_traits<T&>
{
    T* _p;
    pointer_reference_traits(const T* p)
    {
        _p = const_cast<T*>(p);
    }
    operator T&(){return *_p;}
};

template<typename T>
struct pointer_reference_traits<const T&>
{
    T* _p;
    pointer_reference_traits(const T* p)
    {
        _p = const_cast<T*>(p);
    }
    operator const T&(){return *_p;}
};

template<typename T>
struct pointer_reference_traits<T*>
{
    T* _p;
    pointer_reference_traits(const T& p)
    {
        _p = const_cast<T*>(&p);
    }
    operator T*(){return _p;}
};

template<typename T>
struct pointer_reference_traits<const T*>
{
    T* _p;
    pointer_reference_traits(const T& p)
    {
        _p = const_cast<T*>(&p);
    }
    operator const T*(){return _p;}
};

/////////////////////////////////


NAMESPACE_TRAITS_END
#endif

########################


########################
// mfunction_traits.hpp

#ifndef MFUNCTION_TRAITS_INCLUDE
#define MFUNCTION_TRAITS_INCLUDE

#include "traits_config.hpp"

NAMESPACE_TRAITS_BEGIN

template<typename Function> struct mfunction_traits_helper;


template<typename Classtype,typename R>
struct mfunction_traits_helper<R(Classtype::*)()>
{
    enum{arity = 0};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg1)>
{
    typedef Arg1 arg1;

    enum{arity = 1};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg2,Arg1)>
{
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 2};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg3,Arg2,Arg1)>
{
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 3};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 4};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 5};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 6};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 7};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 8};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 9};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 10};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 11};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 12};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 13};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 14};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 15};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg16,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg16,Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg16 arg16;
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 16};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg17,
    typename Arg16,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg17,Arg16,Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg17 arg17;
    typedef Arg16 arg16;
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 17};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg18,
    typename Arg17,
    typename Arg16,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg18,Arg17,Arg16,Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg18 arg18;
    typedef Arg17 arg17;
    typedef Arg16 arg16;
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 18};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg19,
    typename Arg18,
    typename Arg17,
    typename Arg16,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg19,Arg18,Arg17,Arg16,Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg19 arg19;
    typedef Arg18 arg18;
    typedef Arg17 arg17;
    typedef Arg16 arg16;
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 19};
    typedef R result_type;
    typedef Classtype class_type;
};

template<typename Classtype,typename R,
    typename Arg20,
    typename Arg19,
    typename Arg18,
    typename Arg17,
    typename Arg16,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct mfunction_traits_helper<R(Classtype::*)(Arg20,Arg19,Arg18,Arg17,Arg16,Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg20 arg20;
    typedef Arg19 arg19;
    typedef Arg18 arg18;
    typedef Arg17 arg17;
    typedef Arg16 arg16;
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 20};
    typedef R result_type;
    typedef Classtype class_type;
};


template<typename _MFunctionP_Type>
struct mfunction_traits : public mfunction_traits_helper<_MFunctionP_Type>
{
    typedef _MFunctionP_Type MFunctionP_Type;
};

NAMESPACE_TRAITS_END
#endif

########################

 


########################
//mem_to_fun_converter.hpp

#ifndef MEM_TO_FUN_CONVERTER_INCLUDE
#define MEM_TO_FUN_CONVERTER_INCLUDE

/*@brief:
    换成员函数指针类型转为普通函数类型*/

#include "traits_config.hpp"
#include "mfunction_traits.hpp"

NAMESPACE_TRAITS_BEGIN


template<int Arity, typename funtype>
struct mem_to_fun_converter_helper;

template<typename funtype>
struct mem_to_fun_converter_helper<0,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef typename _traits::result_type(*FunctionP_Type)();
};

template<typename funtype>
struct mem_to_fun_converter_helper<1,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef typename _traits::result_type(*FunctionP_Type)(typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<2,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef typename _traits::result_type(*FunctionP_Type)(typename _traits::arg2,typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<3,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef typename _traits::result_type(*FunctionP_Type)(typename _traits::arg3,typename _traits::arg2,typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<4,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<5,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<6,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<7,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<8,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<9,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<10,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<11,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<12,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<13,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<14,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<15,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<16,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg16,
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<17,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg17,
        typename _traits::arg16,
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<18,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg18,
        typename _traits::arg17,
        typename _traits::arg16,
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<19,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg19,
        typename _traits::arg18,
        typename _traits::arg17,
        typename _traits::arg16,
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename funtype>
struct mem_to_fun_converter_helper<20,funtype>
{
    typedef mfunction_traits<funtype> _traits;

    typedef
        typename _traits::result_type(*FunctionP_Type)
        (
        typename _traits::arg20,
        typename _traits::arg19,
        typename _traits::arg18,
        typename _traits::arg17,
        typename _traits::arg16,
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename Signature>
struct mem_to_fun_converter
{
    typedef
        typename mem_to_fun_converter_helper<mfunction_traits<Signature>::arity,Signature>::FunctionP_Type
    FunctionP_Type;
};

 

NAMESPACE_TRAITS_END
#endif

########################

 


########################
// function_traits.hpp

#ifndef FUNCTION_TRAITS_INCLUDE
#define FUNCTION_TRAITS_INCLUDE

#include "traits_config.hpp"

NAMESPACE_TRAITS_BEGIN

template<typename Function>
struct function_pointer_traits
{
    typedef Function* FunctionP_Type;
    typedef Function  Function_Type;
};

template<typename Function>
struct function_pointer_traits<Function*>
{
    typedef Function* FunctionP_Type;
    typedef Function  Function_Type;
};

template<typename Function> struct function_traits_helper;

template<typename R>
struct function_traits_helper<R(*)()>
{
    enum{arity = 0};
    typedef R result_type;
};

template<typename R,typename Arg1>
struct function_traits_helper<R(*)(Arg1)>
{
    typedef Arg1 arg1;

    enum{arity = 1};
    typedef R result_type;
};

template<typename R,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg2,Arg1)>
{
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 2};
    typedef R result_type;
};

template<typename R,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg3,Arg2,Arg1)>
{
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 3};
    typedef R result_type;
};

template<typename R,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 4};
    typedef R result_type;
};

template<typename R,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 5};
    typedef R result_type;
};

template<typename R,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 6};
    typedef R result_type;
};

template<typename R,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 7};
    typedef R result_type;
};

template<typename R,typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 8};
    typedef R result_type;
};

template<typename R,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 9};
    typedef R result_type;
};

template<typename R,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 10};
    typedef R result_type;
};

template<typename R,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 11};
    typedef R result_type;
};

template<typename R,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 12};
    typedef R result_type;
};

template<typename R,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 13};
    typedef R result_type;
};

template<typename R,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 14};
    typedef R result_type;
};

template<typename R,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 15};
    typedef R result_type;
};

template<typename R,
    typename Arg16,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg16,Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg16 arg16;
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 16};
    typedef R result_type;
};

template<typename R,
    typename Arg17,
    typename Arg16,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg17,Arg16,Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg17 arg17;
    typedef Arg16 arg16;
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 17};
    typedef R result_type;
};

template<typename R,
    typename Arg18,
    typename Arg17,
    typename Arg16,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg18,Arg17,Arg16,Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg18 arg18;
    typedef Arg17 arg17;
    typedef Arg16 arg16;
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 18};
    typedef R result_type;
};

template<typename R,
    typename Arg19,
    typename Arg18,
    typename Arg17,
    typename Arg16,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg19,Arg18,Arg17,Arg16,Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg19 arg19;
    typedef Arg18 arg18;
    typedef Arg17 arg17;
    typedef Arg16 arg16;
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 19};
    typedef R result_type;
};

template<typename R,
    typename Arg20,
    typename Arg19,
    typename Arg18,
    typename Arg17,
    typename Arg16,
    typename Arg15,
    typename Arg14,
    typename Arg13,
    typename Arg12,
    typename Arg11,
    typename Arg10,
    typename Arg9,
    typename Arg8,typename Arg7,typename Arg6,typename Arg5,typename Arg4,typename Arg3,typename Arg2,typename Arg1>
struct function_traits_helper<R(*)(Arg20,Arg19,Arg18,Arg17,Arg16,Arg15,Arg14,Arg13,Arg12,Arg11,Arg10,Arg9,Arg8,Arg7,Arg6,Arg5,Arg4,Arg3,Arg2,Arg1)>
{
    typedef Arg20 arg20;
    typedef Arg19 arg19;
    typedef Arg18 arg18;
    typedef Arg17 arg17;
    typedef Arg16 arg16;
    typedef Arg15 arg15;
    typedef Arg14 arg14;
    typedef Arg13 arg13;
    typedef Arg11 arg11;
    typedef Arg10 arg10;
    typedef Arg9 arg9;
    typedef Arg8 arg8;
    typedef Arg7 arg7;
    typedef Arg6 arg6;
    typedef Arg5 arg5;
    typedef Arg4 arg4;
    typedef Arg3 arg3;
    typedef Arg2 arg2;
    typedef Arg1 arg1;

    enum{arity = 20};
    typedef R result_type;
};

 

template<typename _Function_Type>
struct function_traits : public function_traits_helper<typename function_pointer_traits<_Function_Type>::FunctionP_Type>
{
    typedef typename function_pointer_traits<_Function_Type>::Function_Type Function_Type;
    typedef typename function_pointer_traits<_Function_Type>::FunctionP_Type FunctionP_Type;
};


NAMESPACE_TRAITS_END
#endif

########################


########################
// fun_to_mem_converter.hpp

#ifndef FUN_TO_MEM_CONVERTER_INCLUDE
#define FUN_TO_MEM_CONVERTER_INCLUDE

#include "traits_config.hpp"
#include "function_traits.hpp"

NAMESPACE_TRAITS_BEGIN

template<int Arity,typename classtype, typename funtype>
struct fun_to_mem_converter_helper;

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<0,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef typename _traits::result_type(classtype::*MFunctionP_Type)();
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<1,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef typename _traits::result_type(classtype::*MFunctionP_Type)(typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<2,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef typename _traits::result_type(classtype::*MFunctionP_Type)(typename _traits::arg2,typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<3,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef typename _traits::result_type(classtype::*MFunctionP_Type)(typename _traits::arg3,typename _traits::arg2,typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<4,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<5,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<6,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<7,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<8,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<9,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<10,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<11,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<12,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<13,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<14,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<15,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<16,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg16,
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<17,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg17,
        typename _traits::arg16,
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<18,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg18,
        typename _traits::arg17,
        typename _traits::arg16,
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<19,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg19,
        typename _traits::arg18,
        typename _traits::arg17,
        typename _traits::arg16,
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename classtype,typename funtype>
struct fun_to_mem_converter_helper<20,classtype,funtype>
{
    typedef function_traits<funtype> _traits;

    typedef
        typename _traits::result_type(classtype::*MFunctionP_Type)
        (
        typename _traits::arg20,
        typename _traits::arg19,
        typename _traits::arg18,
        typename _traits::arg17,
        typename _traits::arg16,
        typename _traits::arg15,
        typename _traits::arg14,
        typename _traits::arg13,
        typename _traits::arg12,
        typename _traits::arg11,
        typename _traits::arg10,
        typename _traits::arg9,
        typename _traits::arg8,
        typename _traits::arg7,
        typename _traits::arg6,
        typename _traits::arg5,
        typename _traits::arg4,
        typename _traits::arg3,
        typename _traits::arg2,
        typename _traits::arg1);
};

template<typename Signature, typename classtype>
struct fun_to_mem_converter
{
    typedef
        typename fun_to_mem_converter_helper<function_traits<Signature>::arity,classtype,typename function_traits<Signature>::FunctionP_Type>::MFunctionP_Type
    MFunctionP_Type;
};


NAMESPACE_TRAITS_END
#endif

本文永久更新链接地址

相关内容

    暂无相关文章