使用从位置m开始的Arg ...的n个参数 [英] Using n arguments from Args... starting from position m
问题描述
说我有不同的函数,它们有可变数量的参数。第一个参数总是通过其他方式获得的指针。所有其他参数我使用模板包扩展通过另一个模板获得。
我用于调用这些函数的模板如下:
Say I have different functions, which have a variable number of arguments. The first argument is always a pointer obtained through other means. All other arguments I obtain through another template using template pack expansion.
Template that I use for calling these functions is as follows:
template<typename RT, typename... Args>
inline RT call(RT(*function)(Args...))
{
return function(pointer_from_somewhere, bind_argument<Args>::get_arg()...);
}
这显然不会编译,因为它执行所有参数的模板扩展,
由于我总是通过其他方式获取第一个参数,我将如何对进行模板包扩展sizeof ...(Args) - 1
参数,从第二个参数开始?
This obviously doesn't compile, as it performs template expansion for all arguments, thus there being too many arguments.
Since I always obtain the first argument through other means, how would I do template pack expansion for sizeof...(Args) - 1
arguments, starting from the 2nd argument?
EDIT:
为了演示的目的,它可能是相关的,第一个参数(指针)是reinterpret_cast总是对第一个参数的类型。我使用 std :: tuple_element< 0,std :: tuple< Args ...>> :: type
找出第一个参数的类型。
$ b
While the template is slimmed down for demonstration purposes, it might be relevant, that the 1st argument (the pointer) is reinterpret_cast'ed always to the type of first argument. I use std::tuple_element<0, std::tuple<Args...>>::type
for finding out the type of the 1st argument.
推荐答案
这是您要查找的吗?
template<typename RT, typename A0, typename... Args>
inline RT call(RT(*function)(A0, Args...))
{
return function(pointer_from_somewhere, bind_argument<Args>::get_arg()...);
}
这篇关于使用从位置m开始的Arg ...的n个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!