In the model m
I want to create a kind of a closure that holds the additional argument v
and provides an operator() that calls func
:
class _Closure_func
{
double &v;
public:
_Closure_func(double &v)
: v(v)
{}
double operator()(double u) {
return func(u, v);
}
};
This way the code for the function call in model m
can look like:
y = feval(_Closure_func(2.0), 1.0 + u);
The code for the function feval can look like
template <class _fnptr_part>
double feval(_fnptr_part f, double u)
{
double y;
y = f(u);
return y;
}
The problem is the missing type information for for u
and v
(at least for u
) in PARTEVALFUNC
when generating code the closure. The function itself can be implemented with template, because Modelica does not enforce inheritance of func
from part
. But a specific name containing the interface function part
should be used -- this is not known in the current FUNTION_PTR
.