将C lambdas存储为二进制数据
发布时间:2020-12-16 10:03:18 所属栏目:百科 来源:网络整理
导读:我目前正在尝试扩展sqrat(松鼠绑定实用程序)以满足将lambda绑定到松鼠的需求. 我得到的问题是,虽然存储和调用代码可以知道lambda的签名(这是设置将执行lambda的函数的代码) // Arg Count 0template class R,class Args,class AritySQFUNCTION SqMemberLambda
我目前正在尝试扩展sqrat(松鼠绑定实用程序)以满足将lambda绑定到松鼠的需求.
我得到的问题是,虽然存储和调用代码可以知道lambda的签名(这是设置将执行lambda的函数的代码) // Arg Count 0 template <class R,class Args,class Arity> SQFUNCTION SqMemberLambdaFuncDetail(R result,Args args,boost::mpl::integral_c<unsigned int,1> arity) { return &SqLambda<R>::template Func0<false>; } // Arg Count 1 template <class R,2> arity) { return &SqLambda<R>::template Func1<boost::mpl::at_c<Args,1>::type,2,false>; } template <class F> SQFUNCTION SqMemberLambdaFunc(F f) { typedef boost::function_types::result_type<decltype(&F::operator())>::type result_t; typedef boost::function_types::function_arity< decltype(&F::operator())> arity_t; typedef boost::function_types::parameter_types< decltype(&F::operator())>::type args_t; result_t result; args_t args; arity_t arity; return SqMemberLambdaFuncDetail<result_t,args_t,arity_t>(result,args,arity); } lambda本身需要以匿名形式存储,作为二进制数据,我似乎无法找到这样做的方法. 解决方法
Lambdas不能保证是标准布局(所以看看它们的位是不合法的),它们的内容也不是内省的.
如果您想要可以序列化然后远程运行的代码,请使用脚本引擎.有很多,有些与C很好地互动. 或者只是提升凤凰,这是一个lambda-esque的可反映的C -esque代码. 但是,如果您唯一的问题是通常使用签名R(Args …)存储lambda的副本,只需使用std :: function< R(Args ...)>. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |