|
Boost Users : |
Subject: Re: [Boost-users] [bind] How do I....?
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2009-08-18 05:53:45
On Tue, Aug 18, 2009 at 10:41 AM, Neil Groves <neil_at_[hidden]>wrote:
>
>
> 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(...).
>
Excellent - attack from the opposite direction, I'd not thought of that
approach!
>
> The other is to use RangeEx (shameless plug) thus:
>
> using namespace boost::adaptors;
> boost::for_each(v | indirected, f);
>
Ah, if only I could! Doesn't that just demonstrate why RangeEx is so eagerly
awaited.
Thanks Neil
- Rob.
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