Q : std::同一数组内具有不同类型的函数
Q : std::function with different type inside the same array
我正在研究一个实体组件系统库以用于学习目的,我正在尝试对我的设计进行重大更改。
我将通过对多个update
函数的一个update
调用来拆分class System
。但这些功能可以是任何东西,无论是否功能。所以我以许多不同的std::function
类型结束。
出于性能原因,我真的不想使用tuple
(或者它真的很有效,告诉我)。我想使用std::array
,但是如何将各种std::function
放在一起?好吧,实际上这是一个包含std::function
的struct
,但正因为如此,struct
得到相同类型的问题。
如果数组可以在编译时生成(没有参数),那将是最好的。
有一个插图(不是真正的代码)我希望它如何工作。
//Function to add a function in the list [[Call by User]]
addSystemBloc<Position, Speed>(function(ArgIDontKnow, Position, Speed), otherThings);
//Function to generate a structure (probably a graph) linked to the array
generateGraph();
//Inside the initialization of the System using the function we just add [[ Call by User ]]
addArgument(id, arg); //id is not really nice, and this guy know the function he wants to add an arg (with std::bind)
//Somwhere in the main loop [[ Call by Library ]]
invoke(func, Position, Speed);
无论如何,谢谢
数组
是指定类型的值的固定长度序列。元组是指定类型的值的固定长度序列。没有方法的结构是指定类型的值的固定长度序列。
它们在检索元素(即常量)和移动/复制(即大小(事物)字节)方面都具有相同的性能特征。
您在想象什么"性能问题"?
请参阅:http://en.cppreference.com/w/cpp/language/object
相关文章:
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- 将C++子类成员函数(虚拟实现)传递给 C 类型函数指针
- C++ 这里有一个返回 (24) 的布尔返回类型函数
- 使用SFINAE来检测void返回类型函数的存在
- 如何获取同一类函数中类成员的函数指针?
- 使用此类型函数有什么优势
- 为什么此函数通过类型函数指针调用后,呼叫明智地行为
- 如何使用无类型函数指针调用C++成员函数
- 模板返回类型函数如何在C++中工作
- 具有通用类型函数的动态库[C ]
- 如何在返回类型函数模板的专用化中使用派生类型?( "couldn't infer template argument" )
- Bon appetit :从 int 返回类型函数在 main() 中打印字符串
- 对于需要其他模板参数的类型函数的部分模板专业化
- c++错误的参数类型-函数指针
- 延迟评估模板类型函数
- 在引用或指针返回类型函数上输入
- 具有指针数据类型的非类型函数模板参数
- STL中使用的C++自定义比较类型(函数谓词与较少结构)
- C++模板基类的非类型函数模板的 using 声明
- 字符串到类型函数,模板专用化使调用统一