Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-01-07 17:51:09


Server Levent Yilmaz wrote:

> As a side discussion, well it is kind of off topic but now that you
> brought it up, there was a case where I couldn't get away with using
> member pointers and needed this pointer algebra. I'd appreciate any
> idea on this. The problem is simple. Take this struct,
>
> struct A { double a[3]; }
>
> For, this I needed to callback, say, a[2]. A callback facility
> designed with member pointers wouldn't be able to handle this case.
> Right?

You are right, there is no way to take a member pointer to a[2]. You need

int main()
{
    A obj = { 1, 2, 3 };

    namespace ll = boost::lambda;

    boost::function<double(const A&)> f = ll::bind( &A::a, ll::_1 )[ 2 ];

    foo( f, obj );
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net