On Tue, Aug 18, 2009 at 10:41 AM, Neil Groves
<neil@grovescomputing.com> wrote:
On Tue, Aug 18, 2009 at 10:07 AM, Robert Jones
<robertgbjones@gmail.com> 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.