|
Boost : |
Subject: Re: [boost] Determining interest in Delegates submission
From: Jared McKee (jared.mckee_at_[hidden])
Date: 2011-09-08 10:46:08
On Thu, Sep 8, 2011 at 10:19 AM, Jeffrey Lee Hellrung, Jr.
<jeffrey.hellrung_at_[hidden]> wrote:
>
> On Wed, Sep 7, 2011 at 7:48 PM, Jared McKee <jared.mckee_at_[hidden]> wrote:
>
> > I would like to determine interest in a possible library submission.
> >
> > I have written some code which converts a member function and object
> > pointer
> > combination to a free function for use in C style callbacks. It has some
> > limitations which I will describe shortly.
> >
> > The basic idea is to be able to convert:
> >
> > R (B::*)(T0,T1,
) and B*
> >
> > to
> >
> > R (*)(T0,T1,
)
> >
> > Here's an example usage:
> >
> > class foo {
> > int x;
> > int test(int v) {return x + v;}
> > };
> >
> > foo* a = new foo;
> > a->x = 3;
> > int (*f)(int) = delegate(a, &foo::inc);
> > cout << f(4) << endl; // outputs "7"
> >
> [...snip implementation notes...]
>
> I admit I only glossed over your implementation notes, but it looks like
> this would be very similar to (or...the same as...?) a bound (e.g., via
> Boost.Bind) boost::mem_fn:
>
> http://www.boost.org/doc/libs/1_47_0/libs/bind/mem_fn.html
>
> Is that accurate?
Good question. I believe the approach in boost::mem_fn is to create
C++ functor objects which are structs with operator() overloaded.
These functors are not compatible with straight C function pointers.
My implementation returns C function pointers, not functors.
Here's a discussion about the topic:
http://stackoverflow.com/questions/1840029/passing-functor-as-function-pointer
>
> By the way, this is my first active participation in any open source project
> > :)
> >
> > Jared
> >
>
> Welcome!
>
> - Jeff
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk