
Peter I do not have a boost solution. I do have one using FC++, which was considered but not included in Boost. See http://www-static.cc.gatech.edu/~yannis/fc++/ The code looks like this: #include <iostream> #include "fcpp/prelude.h" int foo(int i) { return i; } int main() { std::cout << fcpp::ptr_to_fun(&foo)(1) << std::endl; // It can also be saved as an object. fcpp::Fun1<int,int> wrap_foo = fcpp::ptr_to_fun(&foo); std::cout << wrap_foo(1) << std::endl; return 0; } where fcpp points to the installation of FC++. There exists a "boostified" version of FC++ which will do the same. I hope this helps. John Fletcher Peter Soetens wrote:
Hi,
I'm desperately seeking for doing this conversion using the boost libraries. User code often provides a function pointer, while library code often works with function types. For example (function_conversion does the 'magic' here):
int foo(int);
template<class T, class R = typename function_conversion<T>::type > boost::function<R> function_wrapper(T t) { return boost::function<R>(t); }
Such that the user can write:
function_wrapper( &foo )(1);
Thus no longer needs to specify the int(int) function type to boost::function.
Is it possible to construct such a 'function_conversion' type ?
Any answer is greatly appreciated, Peter