1
我试图初始化一个参数列表,用于fusion :: invoke。 的ARG游戏的所有形式:如何迭代boost :: fusion序列?
template <typename Type>
struct ArgWrapper
{
inline ArgWrapper(){}
inline void Setup(lua_State*L,int idx)
{
//setup this value from the lua state...
//in reality this class is specialised for different lua types
}
operator Type(){return value;}
Type value;
};
所以我可以做,例如
int add(int a,int b){return a+b;}
fusion::vector<ArgsWrapper<int>,ArgsWrapper<int> > v;
fusion::at_c<0>(v).value=1;
fusion::at_c<1>(v).value=2;
std::cout<<fusion::invoke(add,v)//prints 3
但是,如果我有型FusionListType的融合序列,在那里我知道序列中的每个类型一个类型的ArgWrapper,我如何遍历该列表并在每个元素上调用Setup函数(我只有一个lua_State指针,并希望将它用作安装程序的第一个参数,并且我想使用序列中的位置作为第二个参数)。
因此,对于大小为3的向量我想要得到的逻辑是:
lua_State*L;
fusion::at_c<0>.Setup(L,1);
fusion::at_c<1>.Setup(L,2);
fusion::at_c<2>.Setup(L,3);
我曾尝试:
template<typename ArgWrapperType,int N>
void FillArgWrapper(ArgWrapperType arg,lua_State*L)
{
fusion::at_c<N>(arg).Setup(L,N+1);
}
template<typename ArgWrapperType>
void FillArgWrapper<ArgWrapperType,0>(ArgWrapperType arg,lua_State*L)
{
fusion::at_c<0>(arg).Setup(L,1);
}
但这无法编译,说function template partial specialisation ‘FillArgWrapper<ArgWrapperType, 0>’ is not allowed
。
在此先感谢。