Boost logo

Boost Users :

Subject: Re: [Boost-users] [bind] How do I....?
From: Neil Groves (neil_at_[hidden])
Date: 2009-08-18 05:41:02


On Tue, Aug 18, 2009 at 10:07 AM, Robert Jones <robertgbjones_at_[hidden]>wrote:

> Use bind to call a free function on a vector of shared_ptrs?
>
> struct A { };
> void f(const A&);
> std::vector<boost::shared_ptr<A> > v;
>
> for_each(v.begin(), v.end(), boost::bind(f, ???? ) );
>
> what goes where ???? is?
>

Two tactics spring to mind.

One is to use boost::make_indirect_iterator on v.begin() and v.end() and
just pass in f instead of the boost::bind(...).

The other is to use RangeEx (shameless plug) thus:

using namespace boost::adaptors;
boost::for_each(v | indirected, f);

>
> Thanks, Rob.
>

Regards,
Neil Groves

>
> _______________________________________________
> 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