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

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;
};

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

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