Boost Users :
Subject: Re: [Boost-users] [lambda]How can I call function of objects in std::list while using std::for_each?
From: Ç®ÏþÃ÷ (kyleqian_at_[hidden])
Date: 2009-03-23 04:24:31
I think that your advice is a good choice. Using a function object is more
However, if some one know how to do this using Lambda or Bind, please tell
me. I want to know it. thanks!
2009/3/23 Christopher Currie <christopher_at_[hidden]>
> On Sun, Mar 22, 2009 at 8:52 PM, Ç®ÏþÃ÷ <kyleqian_at_[hidden]> wrote:
> > I am sorry that I did not figure out the whole intention. Beside calling
> > member function, I hope to delete the object immediately.
> > I wrote the code at first time:
> > std::for_each( items.rbegin(), items.rend(),
> > (_1->*&DiscardableItem::Discard, bind(delete_ptr(), _1)) );
> > after for_each, objects deleted, but Discard function did not been
> > If using Bind can do the same thing, please tell me. thanks!
> > 2009/3/23 Alex MDC <alex.mdc_at_[hidden]>
> At this point, though you probably *can* do what you want with bind,
> you may want to consider if it will be easier (and clearer in intent)
> to simple write a function object that implements your desired
> struct Discarder : std::unary_function<DiscardableItem*,void>
> void operator()( DiscardableItem * pd ) const
> delete pd;
> std::for_each( items.rbegin(), items.rend(), Discarder() );
> Boost-users mailing list
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