Boost logo

Boost :

From: John Fletcher (J.P.Fletcher_at_[hidden])
Date: 2006-07-07 07:54:16


I do not have a boost solution. I do have one using FC++, which was
considered but not included in Boost. See

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

Boost list run by bdawes at, gregod at, cpdaniel at, john at