In brief: From a C++ base-class pointer which points to an instance of a derived class, how can one determine at run-time whether a non-pure virtual functio
I don't know how to do such detection, but did you consider use of static polymorphism instead? Optimizations can be done at compile-time if every virtual method of Equation is replaced with a template "policy" with default value.
//default implementation of a virtual method turned into a functor
//which optionally takes a reference to equation
class DefaultFunctor1
{
public:
//...
double operator()(double x) { return log(x); }
};
template
class Equation
{
public:
typedef F1 Functor1;
//...
private:
F1 f1;
};
class Solver
{
public:
//....
template
void solve(Equation& eq)
{
Loki::Int2Type<
Loki::IsSameType::value
> selector;
//choose at compile time appropriate implementation among overloads of doSolve
doSolve(selector);
}
private:
//.... overloads of doSolve here
};
int main()
{
Equation<> eq;
Solver solver;
solver.solve(eq); //calls optimized version
Equation my_eq;
solver.solve(my_eq); //calls generic version
return 0;
}