I'm wondering if such a thing is even possible in C++11, passing appropriate amount and type of arguments to a function when for example you have:
template <typename R, typename ... Types>
constexpr std::integral_constant<unsigned, sizeof ...(Types)> getArgumentCount( R(*f)(Types ...))
{
return std::integral_constant<unsigned, sizeof ...(Types)>{};
}
void foo(std::string first, double second, std::string third);
void bar(std::string first, std::string second);
void baz(std::string first, int c);
void passArgs(std::vector<std::string> arguments)
{
//Get arguments count for function foo, do the same for the others
size_t foo_count = decltype(getArgumentCount(foo))::value;
//Here pass appropriate amount of arguments to foo,bar and baz and
//convert to appropriate type using for example std::stoi and
//std::stod when the argument is int or double
Magic(foo,arguments,foo_count);
}
int main()
{
}
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire