Re: [Boost-users] [boost] Convert function pointer type to function type

Quoting Peter Dimov:
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. [...]
One obvious way is
template<class F> boost::function<F> function_wrapper( F * pf ) { return boost::function<F>( pf ); }
but a more interesting question is why do you need a function_wrapper at all. Everything that you could do with the returned function<F> (call it) is also possible with pf itself.
Looking at the simplicity of that answer, this was clearly a boost-users question :-]. Sorry. This was a minimalistic example, removing the context. The big picture uses boost::function<F> to store partially bound objects, since this is a way to store the result of boost::bind for later use in a not templated class. I got confused by the boost::function_traits<T>, which only takes a "function type" and not a "function pointer type." I assumed one was not convertible to the other. I tried using boost::remove_pointer<F>, which didn't work and confirmed back then my assumption (confusingly, is_pointer<F> did work, but I could not remove it using type_traits...) My books write about function pointer types but do not mention 'function types'. These concepts appear to me underdocumented in standard C++ works. *Thanks a lot*. Peter -- www.fmtc.be ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
participants (1)
-
Peter Soetens