[C++-sig] Re: Methods returning & taking pointers to functions
David Abrahams
dave at boost-consulting.com
Fri Oct 3 23:53:19 CEST 2003
"Niall Douglas" <s_sourceforge at nedprod.com> writes:
> I /think/ these don't compile properly ie; lots of compiler warnings.
> Unfortunately a mechanism of specifying a sort function is
> commonplace in my library and ultimately I'll really need it.
>
> I see a two pronged approach: (i) make a pointer to a function an
> opaque type and (ii) write a thunk which invokes an arbitrary python
> function. The latter, through some small alterations to the base
> library, could be entirely driven by parameters (all I need is a
> pointer to the thing calling the sort function).
>
> Has anyone else tried this? Is it even possible?
I think what you're asking for is an automatic conversion from a
Python callable object to a C++ function pointer.
Well, no, it isn't possible, at least not in a reliable way. That's
because a C++ function pointer can't have any associated data, and
you'd need some way to bind the callable Python object to it.
If you can change your interface to use, say,
boost::function2<bool, T, T>
I think we can come up with a solution.
> If BP can't wrap methods taking or receiving pointers to functions,
> then it's a non- starter.
It may be that. This isn't a Boost.Python issue. Search back in the
archives for posts about FLTK if you want more details.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list