I've found similar cases, but they usually ended up doing something along the lines of what I (think) I'm doing here.
I want to be able to call a function with one or more parameters, obviously, if the function exists with overloads with multiple parameters, the correct version cannot be deduced without help.
As I am specifying the number of arguments as well, I figured this would be enough information for the compiler to deduce the correct overload. This doesn't seem to be the case and I hope you may be able to show me why.
the code: http://ift.tt/1wj24q8
#include <iostream>
#include <type_traits>
#include <functional>
template < typename R, typename... A, typename... Args >
typename std::enable_if< sizeof...( A ) == sizeof...( Args ), R >::type
call_my_function( R(*func)(A...), Args ...a )
{
return func( a... );
}
int arg_count() { return 0; }
int arg_count(int) { return 1; }
int arg_count(int,int) { return 2; }
int main()
{
std::cout << call_my_function( arg_count, 0 ) << std::endl;
return 0;
}
I short, I tried to have all functions which have a different argument count than the number of arguments I supplied, fail by means of SFINAE. But it seems they are considered anyway and the ambiguity remains.
Aucun commentaire:
Enregistrer un commentaire