Reputation: 35
I'm looking for a way to create a type expression for a std::tuple representing the arguments required by a function. Consider the following:
template<typename F, typename ...args>
void myfunction(F&& function, A... args)
{
std::tuple</*???*/> arguments;
populate_tuple(arguments,args...);
return apply(function,arguments);
}
... where F is a normal function type, apply() is a function that applies the arguments to the function, and populate_tuple() does some work on the arguments (including type conversions) before populating the tuple with the final arguments for the call to the function.
Note: I can't use args...
in the declaration of the tuple, because these are not the types that the function is expecting - populate_tuple() does the conversion.
It feels to me as though the compiler has everything it needs to do this, but I don't know if the language supports it. Any ideas? All help appreciated.
Upvotes: 0
Views: 50
Reputation: 41770
Does this work?
template<typename F, typename ...Args>
void myfunction(F&& function, Args&&... args) {
return apply(std::forward<F>(function), std::make_tuple(std::forward<Args>(args)...));
}
Upvotes: 0
Reputation: 52471
Something along these lines, perhaps:
template <typename T> struct TupleOfArguments;
template <typename R, typename ... Args>
struct TupleOfArguments<R(Args...)> {
typedef std::tuple<Args...> type;
};
Upvotes: 1