Git   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了variables模板:迭代types/模板参数大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

最近我一直在使用libffi ,因为它使用了C API,所以任何抽象都是通过使用void指针(好的C)来完成的。 我正在创build一个类(使用variaDic模板),它利用这个API。 类声明如下:(其中Ret =返回值, Args =函数参数)

template <typename Ret,typename... Args> class Function

在这个类中,我也声明了两个不同的函数(简化):

Ret Call(Args... args); // Calls the wrapped function void CallBACkBind(Ret * ret,void * args[]); // The libffi callBACk function (it's actually static...)

我希望能够使用来自CallBACkBind Call ; 这是我的问题。 我不知道我应该如何将void*数组转换为模板参数列表。 这是我想要的更多或更less:

CallBACkBind(Ret * ret,void * args[]) { // I want to somehow expand the array of void pointers and convert each // one of them to the corresponding template type/argument. The length // of the 'void*' vector equals sizeof...(Args) (variaDic template argument count) // Cast each of one of the pointers to their original type *ret = Call(*((typeof(Args[0])*) args[0]),*((typeof(Args[1])*) args[1]),... /* and so on */); }

如果这是不可行的,是否有任何解决方法或不同的解决scheR_999_11845@e可用?

在Intellij IDEA for Windows中configurationC ++ SDK

@H_57_0@msi.h为mingw

syscalls添加到Linux的历史?

为什么DirectoryInfo.GetFiles()匹配与掩码不匹配的文件

如何编写一个阻止有害/有害网站的好程序

在机器上find可用的networking端口

win32线程安全队列实现使用本地的Windows API

将JavaFX Stageembedded到C ++ Windows应用程序中

在PC机上使用rs232引脚configuration

c + + GetKeyState()一些键码不工作

你不想迭代类型,你想创建一个参数包,并在一个可变模板中展开它。 你有一个数组,所以你想要的包是一组整数0,1,2 …作为数组索引。

#include <redi/index_tuple.h> template<typename Ret,typename... Args> struct Function { Ret (*wrapped_function)(Args...); template<unsigned... I> Ret dispatch(void* args[],redi::index_tuple<I...>) { return wrapped_function(*static_cast<Args*>(args[I])...); } void CallBACkBind(Ret * ret,void * args[]) { *ret = dispatch(args,to_index_tuple<Args...>()); } };

像这样的东西,使用index_tuple.h

诀窍是CallBACkBind创建一个表示arg位置的整数的index_tuple ,并分派给另一个推导整数的函数,并将这个包展开成一个转换表达式列表,作为包装函数的参数。

大佬总结

以上是大佬教程为你收集整理的variables模板:迭代types/模板参数全部内容,希望文章能够帮你解决variables模板:迭代types/模板参数所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: