mercredi 25 février 2015

Deducing the selected overloaded function type for given argument types

Is it possible to determine the function type of the candidate that overload resolution would select given an overload set and an argument list? For example, given:



char* f(int);
int f(char*);


I would like to be able to write something like:



overload<f, short>::type x;


to declare a variable x of type char* (*)(int).


Is this possible? My first instinct was to write something like this:



template<typename... Args>
struct overload {
template<typename Ret>
static auto deduce(Ret (*fptr)(Args...)) -> decltype(fptr);
};


...but this can't handle non-exact matches (i.e. decltype(overload<int>::deduce(f)) works, but decltype(overload::deduce(<short>(f)) does not).


Aucun commentaire:

Enregistrer un commentaire