
Peter Dimov wrote:
When you construct a boost::function from &HandleClass::handle, what actually gets stored is boost::mem_fn(&HandleClass::handle). See
http://www.boost.org/libs/mem_fn/
Even
std::vector< boost::shared_ptr<HandleClass> > listOfHcs;
will work.
Thanks Peter, makes sense after reading that documentation now. I've actually got another question - I'd really prefer to replace ReturnContainer with an output iterator type. So Extract would look like this: template < class InIterator, class OutIterator, > void Extract(const InIterator & itBegin, const InIterator & itEnd, OutIterator & itOut, boost::function1<OutIterator::value_type, FwdIterator::value_type> f) { for (FwdIterator it = itBegin ;it != itEnd; ++it) { *itOut++ = f(*it); } }; And then you'd typically call Extract with an inserter: Extract(listOfHcs.begin(), listOfHcs.end(), back_inserter(needToFill), &HandleClass::handle); But this doesn't compile because the inserters (at least on my platform) don't define value_type. I'd prefer to take an iterator because it gives greater flexibility (can use inserter, front_inserter or back_inserter) and it more closely models the standard algorithms. However, I need to know the return type of the function and I can't see any way to get it without specifying it as a template parameter. Actually, I think I could use the typedefs that are defined in the inserters to retrieve the container, and then the value type, but this then forces the client to use inserters. Am I overlooking something here? Cheers, Matt