float Minus(float a, float b);
int Minus(int a, int b);
double Minus(double a, double b);
template<Func, P1, P2 >
decltype(declval<Func>()(P1(), P2())) CheckAndDo( Func func, P1 p1, P2 p2)
{
if( p1 < 0 || p2 < 0 )
return decltype(Func(P1,P@)) 0;
return func(p1, p2);
}
// compile failed, because Minus does not belong to an actual type. Compiler cannot know which Function it is
CheckAndDo(&Minus, 10, 5);
//but still we can construct a type which can handle that
class Overload_Minus{
public:
float operator()(float a, float b)
{
return Minus(a,b);
}
int operator()(int a, int b)
{
return Minus(a,b);
}
double operator()(double a, double b)
{
return Minus(a,b);
}
};
// So that now we can calls
Overload_Minus minus;
int a = CheckAndDo(minus, 1, 2);