谈一下关于C++函数包装问题

Posted xiaojack

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了谈一下关于C++函数包装问题相关的知识,希望对你有一定的参考价值。

在C++中,我们经常遇到在某个特定的时刻,需要将函数进行包装调用,尤其是当我们需要将不同签名的函数放到同一个集合时,由于函数签名不一致导致我们不能直接将各式各样的函数指针放到诸如list这样的集合中,因此对函数进行包装就显得格外重要.现在来介绍一下我写的一个函数包装器.

还是需要用到模板技巧,写这种类库没有模板将是不可能实现的任务,大家顺便学习一下模板编写也挺好的.

还是不废话,先上实例,后贴完整类库,这个类库需要用到前面写的萃取和序列化库,当然了,序列化库是可以被替换的,只要满足接口一致.

这里多废话一句:本人致力于写跨平台的C++开源代码,我之前以及现在以及将来上传的所有代码均以hpp文件发布,这种文件的好处就是可以直接包含到源码里使用,而不需要产生各种烦人的dll或者lib.这个库附带了一个scope_guard文件,也是一个很好的安全调用设计,有兴趣的看看

用例代码(看注释基本就可以了):

#include<iostream>
#include "../../traits/traits.hpp"
#include "../../serialization/archive.hpp"
#include "../../call_helper/call.hpp"

using namespace std;

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

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

int main()
{
    // C函数包装
    callhelper::call_helper<int(char, int)> helper1(show);
    helper1.call(a, 6);

    // 类成员函数包装
    Stu stu;
    callhelper::call_helper<int(Stu::*)(char, int), Stu> helper2(&stu,&Stu::show);
    helper2.call(a, 6);



    // 另一种形式的C函数包装
    callhelper::icall* helper3 = new callhelper::ccall<int(char, int)>(show);
    //helper3->call(serialization::default_string_iarchive(str));

    // 另一种形式的类成员函数包装
    callhelper::icall* helper4 = new callhelper::ccall<int(Stu::*)(char, int), Stu>(&stu, &Stu::show);
    //helper4->call(serialization::default_string_iarchive(str));
    
    // 放到同一集合中
    std::list<callhelper::icall*> _list;
    _list.push_back(helper3);
    _list.push_back(helper4);

    std::string str;
    serialization::default_string_oarchive oarc(str);
    oarc & a & 6;

    // 调用
    for (std::list<callhelper::icall*>::iterator iter = _list.begin(); iter != _list.end(); ++iter)
    {
        (*iter)->call(serialization::default_string_iarchive(str));
    }

    delete helper3;
    delete helper4;

    return 0;
}

 

完整的类库截图

技术分享

// call.hpp

#ifndef CALL_INCLUDE
#define CALL_INCLUDE

#include "call_helper.hpp"
#include "param_get_set.hpp"
#include "marshal.hpp"
#include "scope_guard.hpp"
#include "call_wrapper.hpp"
#include "call_container.hpp"

#endif
// call_container.hpp

#ifndef CALL_CONTAINER_INCLUDE
#define CALL_CONTAINER_INCLUDE

#include "call_helper_config.hpp"
#include "call_helper.hpp"

#include <list>
#include <vector>
#include <set>

NAMESPACE_CALL_HELPER_BEGIN


struct basic_call_container
{
    virtual void call(IArchive& iarc)=0;
    virtual ~basic_call_container(){}
};

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

template<typename containertype,typename classtype,typename funtype,int paramc>
struct _call_container : public basic_call_container{};

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

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,0> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call();
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,1> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,2> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,3> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,4> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,5> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,6> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,7> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,8> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,9> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get9,get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,10> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg10 arg10;
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg10> get10(iarc);
        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get10,get9,get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,11> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg11 arg11;
        typedef typename traits::mfunction_traits<funtype>::arg10 arg10;
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg11> get11(iarc);
        param_get<arg10> get10(iarc);
        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get11,get10,get9,get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,12> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg12 arg12;
        typedef typename traits::mfunction_traits<funtype>::arg11 arg11;
        typedef typename traits::mfunction_traits<funtype>::arg10 arg10;
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg12> get12(iarc);
        param_get<arg11> get11(iarc);
        param_get<arg10> get10(iarc);
        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get12,get11,get10,get9,get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,13> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg13 arg13;
        typedef typename traits::mfunction_traits<funtype>::arg12 arg12;
        typedef typename traits::mfunction_traits<funtype>::arg11 arg11;
        typedef typename traits::mfunction_traits<funtype>::arg10 arg10;
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg13> get13(iarc);
        param_get<arg12> get12(iarc);
        param_get<arg11> get11(iarc);
        param_get<arg10> get10(iarc);
        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get13,get12,get11,get10,get9,get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,14> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg14 arg14;
        typedef typename traits::mfunction_traits<funtype>::arg13 arg13;
        typedef typename traits::mfunction_traits<funtype>::arg12 arg12;
        typedef typename traits::mfunction_traits<funtype>::arg11 arg11;
        typedef typename traits::mfunction_traits<funtype>::arg10 arg10;
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg14> get14(iarc);
        param_get<arg13> get13(iarc);
        param_get<arg12> get12(iarc);
        param_get<arg11> get11(iarc);
        param_get<arg10> get10(iarc);
        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get14,get13,get12,get11,get10,get9,get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,15> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg15 arg15;
        typedef typename traits::mfunction_traits<funtype>::arg14 arg14;
        typedef typename traits::mfunction_traits<funtype>::arg13 arg13;
        typedef typename traits::mfunction_traits<funtype>::arg12 arg12;
        typedef typename traits::mfunction_traits<funtype>::arg11 arg11;
        typedef typename traits::mfunction_traits<funtype>::arg10 arg10;
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg15> get15(iarc);
        param_get<arg14> get14(iarc);
        param_get<arg13> get13(iarc);
        param_get<arg12> get12(iarc);
        param_get<arg11> get11(iarc);
        param_get<arg10> get10(iarc);
        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get15,get14,get13,get12,get11,get10,get9,get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,16> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg16 arg16;
        typedef typename traits::mfunction_traits<funtype>::arg15 arg15;
        typedef typename traits::mfunction_traits<funtype>::arg14 arg14;
        typedef typename traits::mfunction_traits<funtype>::arg13 arg13;
        typedef typename traits::mfunction_traits<funtype>::arg12 arg12;
        typedef typename traits::mfunction_traits<funtype>::arg11 arg11;
        typedef typename traits::mfunction_traits<funtype>::arg10 arg10;
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg16> get16(iarc);
        param_get<arg15> get15(iarc);
        param_get<arg14> get14(iarc);
        param_get<arg13> get13(iarc);
        param_get<arg12> get12(iarc);
        param_get<arg11> get11(iarc);
        param_get<arg10> get10(iarc);
        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get16,get15,get14,get13,get12,get11,get10,get9,get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,17> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg17 arg17;
        typedef typename traits::mfunction_traits<funtype>::arg16 arg16;
        typedef typename traits::mfunction_traits<funtype>::arg15 arg15;
        typedef typename traits::mfunction_traits<funtype>::arg14 arg14;
        typedef typename traits::mfunction_traits<funtype>::arg13 arg13;
        typedef typename traits::mfunction_traits<funtype>::arg12 arg12;
        typedef typename traits::mfunction_traits<funtype>::arg11 arg11;
        typedef typename traits::mfunction_traits<funtype>::arg10 arg10;
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg17> get17(iarc);
        param_get<arg16> get16(iarc);
        param_get<arg15> get15(iarc);
        param_get<arg14> get14(iarc);
        param_get<arg13> get13(iarc);
        param_get<arg12> get12(iarc);
        param_get<arg11> get11(iarc);
        param_get<arg10> get10(iarc);
        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get17,get16,get15,get14,get13,get12,get11,get10,get9,get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,18> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg18 arg18;
        typedef typename traits::mfunction_traits<funtype>::arg17 arg17;
        typedef typename traits::mfunction_traits<funtype>::arg16 arg16;
        typedef typename traits::mfunction_traits<funtype>::arg15 arg15;
        typedef typename traits::mfunction_traits<funtype>::arg14 arg14;
        typedef typename traits::mfunction_traits<funtype>::arg13 arg13;
        typedef typename traits::mfunction_traits<funtype>::arg12 arg12;
        typedef typename traits::mfunction_traits<funtype>::arg11 arg11;
        typedef typename traits::mfunction_traits<funtype>::arg10 arg10;
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg18> get18(iarc);
        param_get<arg17> get17(iarc);
        param_get<arg16> get16(iarc);
        param_get<arg15> get15(iarc);
        param_get<arg14> get14(iarc);
        param_get<arg13> get13(iarc);
        param_get<arg12> get12(iarc);
        param_get<arg11> get11(iarc);
        param_get<arg10> get10(iarc);
        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get6(iarc);
        param_get<arg5> get5(iarc);
        param_get<arg4> get4(iarc);
        param_get<arg3> get3(iarc);
        param_get<arg2> get2(iarc);
        param_get<arg1> get1(iarc);

        for (typename containertype::iterator iter=_container.begin();
            iter!=_container.end(); ++iter)
        {
            call_helper<funtype,classtype>& c_helper = (call_helper<funtype,classtype>&)(*iter);
            c_helper.call(get18,get17,get16,get15,get14,get13,get12,get11,get10,get9,get8,get7,get6,get5,get4,get3,get2,get1);
        }
    }
    containertype _container;
};

template<typename containertype,typename classtype,typename funtype>
struct _call_container<containertype,classtype,funtype,19> : public basic_call_container
{
    virtual void call(IArchive& iarc)
    {
        typedef typename traits::mfunction_traits<funtype>::arg19 arg19;
        typedef typename traits::mfunction_traits<funtype>::arg18 arg18;
        typedef typename traits::mfunction_traits<funtype>::arg17 arg17;
        typedef typename traits::mfunction_traits<funtype>::arg16 arg16;
        typedef typename traits::mfunction_traits<funtype>::arg15 arg15;
        typedef typename traits::mfunction_traits<funtype>::arg14 arg14;
        typedef typename traits::mfunction_traits<funtype>::arg13 arg13;
        typedef typename traits::mfunction_traits<funtype>::arg12 arg12;
        typedef typename traits::mfunction_traits<funtype>::arg11 arg11;
        typedef typename traits::mfunction_traits<funtype>::arg10 arg10;
        typedef typename traits::mfunction_traits<funtype>::arg9 arg9;
        typedef typename traits::mfunction_traits<funtype>::arg8 arg8;
        typedef typename traits::mfunction_traits<funtype>::arg7 arg7;
        typedef typename traits::mfunction_traits<funtype>::arg6 arg6;
        typedef typename traits::mfunction_traits<funtype>::arg5 arg5;
        typedef typename traits::mfunction_traits<funtype>::arg4 arg4;
        typedef typename traits::mfunction_traits<funtype>::arg3 arg3;
        typedef typename traits::mfunction_traits<funtype>::arg2 arg2;
        typedef typename traits::mfunction_traits<funtype>::arg1 arg1;

        param_get<arg19> get19(iarc);
        param_get<arg18> get18(iarc);
        param_get<arg17> get17(iarc);
        param_get<arg16> get16(iarc);
        param_get<arg15> get15(iarc);
        param_get<arg14> get14(iarc);
        param_get<arg13> get13(iarc);
        param_get<arg12> get12(iarc);
        param_get<arg11> get11(iarc);
        param_get<arg10> get10(iarc);
        param_get<arg9> get9(iarc);
        param_get<arg8> get8(iarc);
        param_get<arg7> get7(iarc);
        param_get<arg6> get

以上是关于谈一下关于C++函数包装问题的主要内容,如果未能解决你的问题,请参考以下文章

php 一个自定义的try..catch包装器代码片段,用于执行模型函数,使其成为一个单行函数调用

将 python 函数传递给 SWIG 包装的 C++ 代码

用函数指针包装 C++ 代码作为 cython 中的模板参数

我的Android进阶之旅NDK开发之在C++代码中使用Android Log打印日志,打印出C++的函数耗时以及代码片段耗时详情

将图像从 python 包装器传递给 c++ 函数

从非托管 c++ 调用 C# 函数(通过托管包装器)