title: How to wrap a function to fit the required type of another function
body: <p>Consider the following three functions:</p>
  
  <pre><code>using phase_t = Eigen::VectorXd;
  using rhs_t = phase_t (*)(double const &amp;, phase_t const &amp;);
  using step_t = phase_t (*)(rhs_t , phase_t const &amp;, double, double);
  
  Eigen::MatrixXd foo_ee_step(rhs_t rhs, phase_t const &amp;z0);
  Eigen::MatrixXd foo_int(step_t step, rhs_t rhs, phase_t const &amp; z0);
  Eigen::MatrixXd foo_ee(rhs_t rhs, phase_t const &amp;z0);
  </code></pre>
  
  <p>All of them have one argument of the type <code>rhs_t</code>, which I specified in the second line above. In addition one of the functions has a parameter of the type <code>step_t</code> which depends on a parameter of type<code>rhs_t</code>. My problem is that the variable I'd like to pass to <code>foo_ee_step</code>, <code>foo_int</code> and <code>foo_ee</code> has the from</p>
  
  <pre><code>phase_t my_rhs(double const &amp;, phase_t const &amp;, double);
  </code></pre>
  
  <p>Since I cannot change <code>foo_ee_step</code>, <code>foo_int</code> and <code>foo_ee</code> I tried using a lambda to redefine the function in a suitable way</p>
  
  <pre><code>Eigen::MatrixXd some_function(.....):
      auto better_rhs = [&amp;c](double const &amp; a, phase_t const &amp; b){return my_rhs(a,b,c);};
      return foo_ee(better_rhs, m);
  </code></pre>
  
  <p>but this results in </p>
  
  <pre><code>error: cannot convert ‘some_function(....)::&lt;lambda(const double&amp;, const phase_t&amp;)&gt;’ to ‘rhs_t’ {aka ‘Eigen::Matrix&lt;double, -1, 1&gt; (*)(const double&amp;, const Eigen::Matrix&lt;double, -1, 1&gt;&amp;)’}
  </code></pre>
  
  <p>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 <a href="https://stackoverflow.com/questions/28746744/passing-capturing-lambda-as-function-pointer">forbidden</a>... I've read <a href="https://stackoverflow.com/a/7852154/7746905">here</a>, 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 <code>foo_ee_step</code>, <code>foo_int</code> and <code>foo_ee</code>, 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 <code>rhs_t</code>? Are there other techniques to solve this problem? </p>
  
  <p>P.S. Not sure if it is important, but so far I have also tried:</p>
  
  <ol>
  <li>Defining just another function inside <code>some_function</code> that is named <code>better_rhs</code> (which obviously also didn't work).</li>
  <li>Wrap all of this into a class, and use <code>foo_ee_step</code>, etc. as member functions. Then just define another member function <code>better_rhs</code> and call there <code>my_rhs</code>.. This resulted in an error about not being able to pass a non-static member function, but having to call it explicitly... </li>
  </ol>
  
  <p>Any hints on how to proceed are appreciated. </p>