Boost logo

Boost Users :

From: Haroon Khan (haroon.khan_at_[hidden])
Date: 2006-11-30 00:27:07


I managed to solve the problem, as shown in the code below. I had
mixed up the Boost.Bind and Boost.Lambda , and totally confused
myself.

Thanks, Haroon

struct some_functor
{
private:
    int x_;
public:
    some_functor& foo(int x)
    {
        std::cout<<boost::format("Calling %x.%s(%d)\n") % this % __FUNCTION__%x;
        x_=x;
        return *this;
    }

    some_functor &bar()
    {
        std::cout<<boost::format("Calling %x.%s \n")%this%__FUNCTION__;
        std::cout<<boost::format("%x->x=%d\n")%this%x_;
        return *this;
    }
};

void test16()
{
    PRINT_FUNCTION_NAME;
    using namespace boost::lambda;
    bind(&some_functor::bar, var(bind(&some_functor::foo,
var(some_functor()), _1) ) )(boost::cref(1));
    int a[] = {1, 2, 3, 4, 5, 6, 7, 8};
    std::vector<int> v(a, a+sizeof(a)/sizeof(int));

    std::for_each
        ( v.begin(), v.end()
        , bind(&some_functor::bar, var(bind(&some_functor::foo,
var(some_functor()), _1) ) ) );
}

On 11/29/06, Jaakko Järvi <jarvi_at_[hidden]> wrote:
> Can you post a full example (with main, includes and all)?
>
> Jaakko
>
>
>
> On Nov 27, 2006, at 9:41 PM, Haroon Khan wrote:
>
> > Hi,
> > How can we use the Boost::lambda::bind function to behave the same as
> > the following
> >
> > class some_class{
> > public:
> > some_class& foo(int x){....}
> > void bar() {...}
> > }
> >
> > some_class a_object;
> > a_object.foo(x).bar(), where the call to some_class::foo returns a
> > reference to the object.
> >
> > I could use Boost.Bind library to accomplish the above as follows
> > boost::bind(&some_class::bar, boost::bind(&some_class::foo,
> > some_functor(), _1))
> >
> > and I need to do this using boost.lambda.
> >
> > Thanks, Haroon
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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