Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从类型列表子集创建函数指针_C++_Templates_Variadic Templates_Typelist - Fatal编程技术网

C++ 从类型列表子集创建函数指针

C++ 从类型列表子集创建函数指针,c++,templates,variadic-templates,typelist,C++,Templates,Variadic Templates,Typelist,我有一个非常类似于的类型列表实现。如果您不知道类型列表是什么:简而言之,它的行为类似于使用嵌套元组的可变模板。你可以阅读更多关于他们的信息 我想从这个类型列表的子集建立一个函数指针类型。子集由索引列表(任意大小)定义,所需操作在类型列表中查找这些索引,并使用这些类型作为参数定义函数上指针的类型 API看起来像: #include "typelist.h" // typelist definition typedef Typelist<float, Typelist<double, T

我有一个非常类似于的类型列表实现。如果您不知道类型列表是什么:简而言之,它的行为类似于使用嵌套元组的可变模板。你可以阅读更多关于他们的信息

我想从这个类型列表的子集建立一个函数指针类型。子集由索引列表(任意大小)定义,所需操作在类型列表中查找这些索引,并使用这些类型作为参数定义函数上指针的类型

API看起来像:

#include "typelist.h"
// typelist definition
typedef Typelist<float, Typelist<double, Typelist<int, NullType>>> Pixel;

typedef FunctionFromFields<Pixel, 0, 2>::Type field_0_and_2;
// I want the definition above to be equivalent to:
// typedef void (*field_0_and_2)(float*, int*);
#包括“typelist.h”
//类型表定义
typedef类型列表像素;
typedef FunctionFromFields::Type field_0_和_2;
//我希望上述定义等同于:
//typedef void(*字段0和2)(float*,int*);
似乎有理由假设这是可能的,因为在编译时一切都是已知的,但我还没有找到正确的语法

我不想使用可变模板来替换类型列表,但是它们可以用来定义指针类型


有人做过类似的事情吗?

这应该相当容易。首先定义一个
typelist\n
type函数(左为练习;我假设在
typelist.h
中有一个):

模板结构类型列表\u n;
然后使用可变模板构建函数类型:

template<typename TL, int... Is> struct FunctionFromFields {
    typedef void (*Type)(typename typelist_nth<TL, Is>::type *...);
};
模板结构函数fromfields{
typedef void(*Type)(typename类型列表n::Type*…);
};

是的,就是这样。这其实并不难,我只是把自己和语法搞混了。
template<typename TL, int... Is> struct FunctionFromFields {
    typedef void (*Type)(typename typelist_nth<TL, Is>::type *...);
};