C++类型萃取编写技巧(8)


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;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4b11dba9eca97ff5bf235e221cf6c9e1.html