I have a class that uses a reference to a function:
double u( const double& x, const double& y )
{
return x * y;
}
class equation
{
equation( double (&in_u)(const double&, const double&) );
//...
protected:
double (&u)(const double&, const double&);
}
This function would be called something like $10^8$ times during a typical run.
The class goes into a library and the function u
is defined by the user of the library. So I cannot have the function definition inside the class.
I have read this:
(
std::function
) ... has the disadvantage of introducing some (very small) overhead when being called (so in a very performance-critical situation it might be a problem but in most it should not)
Are there any more efficient ways of passing the function u
to the class equation
? And would this count as "a very performance-critical situation"?
Aucun commentaire:
Enregistrer un commentaire