Consider I have the following:
void bar(int a, int b)
{
}
template
void foo(F function, Args... args>
{
function(a
First, we need a function to retrieve the number or arguments the function requires. This is done using function_traits:
template
constexpr std::size_t nb_args() {
return utils::function_traits::arity;
}
And with the help of std::index_sequence, we only dispatch the nb_args
first arguments:
template
void foo_impl(F && f, std::index_sequence, Tup && tup) {
std::forward(f)( std::get(tup)... );
}
template
void foo(F && f, Args&&... args) {
foo_impl(std::forward(f),
std::make_index_sequence()>{},
std::forward_as_tuple(args...) );
}
Demo