
On Fri, Aug 8, 2008 at 14:13, Jesse Perla <jlp400@nyu.edu> wrote:
Is there any way to get a normal function pointer out of a boost::function (with its state and potential bindings)? I want to have the option of calling existing optimization routines that are not functor aware. And hopefully including Fortran and C functions as well? I imagine that any solution to this would be hacky and potentially slow, but it would be nice to have the option without porting every optimization routine.
Boost.Thread needs to pass a plain function pointer to the native libraries, but has a boost::function<void()>. You can probably use the same trick it uses. (Though IIRC, it only works if you can pass a void* data argument that goes along with the function. If all you can pass is a, say, double(*)(double), then you might be somewhat out of luck when it comes to nice solutions. You can always use global variables to pass the state, but those are obviously not nice.)