Consider the following three functions:
using phase_t = Eigen::VectorXd;
using rhs_t = phase_t (*)(double const &, phase_t const &);
using step_t = phase_t (*)(rhs_t , phase_t const &, double, double);
Eigen::MatrixXd foo_ee_step(rhs_t rhs, phase_t const &z0);
Eigen::MatrixXd foo_int(step_t step, rhs_t rhs, phase_t const & z0);
Eigen::MatrixXd foo_ee(rhs_t rhs, phase_t const &z0);
All of them have one argument of the type rhs_t
, which I specified in the second line above. In addition one of the functions has a parameter of the type step_t
which depends on a parameter of typerhs_t
. My problem is that the variable I'd like to pass to foo_ee_step
, foo_int
and foo_ee
has the from
phase_t my_rhs(double const &, phase_t const &, double);
Since I cannot change foo_ee_step
, foo_int
and foo_ee
I tried using a lambda to redefine the function in a suitable way
Eigen::MatrixXd some_function(.....):
auto better_rhs = [&c](double const & a, phase_t const & b){return my_rhs(a,b,c);};
return foo_ee(better_rhs, m);
but this results in
error: cannot convert ‘some_function(....)::<lambda(const double&, const phase_t&)>’ to ‘rhs_t’ {aka ‘Eigen::Matrix<double, -1, 1> (*)(const double&, const Eigen::Matrix<double, -1, 1>&)’}
I think this comes from the fact that I'm trying to pass a lambda that captures something as a function pointer, which seems to be forbidden... I've read here, that one could try to solve this problem by defining a functor. But if I'm not mistaken, for this to work I would need to change foo_ee_step
, foo_int
and foo_ee
, which I can't.. Soo, I don't really know how to tackle this problem.. Is it possible to somehow cast this lambda expression into the form rhs_t
? Are there other techniques to solve this problem?
P.S. Not sure if it is important, but so far I have also tried:
- Defining just another function inside
some_function
that is namedbetter_rhs
(which obviously also didn't work). - Wrap all of this into a class, and use
foo_ee_step
, etc. as member functions. Then just define another member functionbetter_rhs
and call theremy_rhs
.. This resulted in an error about not being able to pass a non-static member function, but having to call it explicitly...
Any hints on how to proceed are appreciated.