Boost logo

Boost Users :

Subject: Re: [Boost-users] Usign boost::bind with a call to member function
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2010-11-30 13:16:45


przemyslaw.sliwa_at_[hidden] wrote:
>
> Hello,
>
> I would like to replace this trivial loop
>
> for(size_t i=0; i<intersection.size(); i++)
> {
> domCcyEventPtrs.push_back(events->event(domCcy, intersection[i]));
> }
>
> with a call to std::transform and boost::bind.
> The events object is actually a boost_shared_ptr<> of a certain type.
> domCcyEventPtrs and intersection are std::vector<> objects. Can this be
> done?

std::transform
( intersection.begin()
, intersection.end()
, std::back_inserter(domCcyEventPtrs)
, boost::bind(&events_type::event, &events, domCcy, _1)
);

depending on what domCcy is and how you want it passed you may need to
wrap it in boost::ref or boost::cref.

Also a more succinct approach would be to use the range library.

Jeff


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