Reputation: 4853
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()...);
}
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:
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.
Upvotes: 1
Views: 71
Reputation: 5230
Is this what you are looking for?
template<typename RT, typename A0, typename... Args>
inline RT call(RT(*function)(A0, Args...))
{
return function(pointer_from_somewhere, bind_argument<Args>::get_arg()...);
}
Upvotes: 2