Boost logo

Boost Users :

Subject: [Boost-users] "apply" member function over collection
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2011-09-17 04:28:53


Consider this:

     // new way, so far so good
     boost::range::for_each (mylist, std::tr1::bind(&C::foo, _1));

// original:
// for(Collection::iterator fi = mylist.begin(); fi != mylist.end(); ++fi) {
// Collection::reference item = *fi;
// item->foo();
// }

I've got a zillion of these one-shot "for" loops, and I was able to change this sample to
use a range::for_each. But, it's still too ackward and will be unfamiliar to other users,
so it has to be "sleek or bust"!

The item type is actually a smart pointer.

Is there a more succinct way of writing it, without needing the extra placeholder to be
mentioned?
The for_each works find as an "apply" except that the member function needs to be adapted;
it won't do that by itself.
I found that boost::range::for_each (Filters,
std::tr1::mem_fn(&VseeMediaFilter::Uninitialize));
compiles too, even though I'll be passing a smart pointer to the resulting adapted
function. But, as mentioned on another thread, mem_fn is deprecated?

How might I write this more tersely, or provide an 'apply' utility of my own that does
what I want?

Thanks,
—John


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