Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-02-04 06:27:03

From: "beatlebum1967" <beatlebum1967_at_[hidden]>
> int val=1;
> std::for_each(testVec.begin(), testVec.end(),
> std::bind2nd(boost::mem_fn
> (&CSwarmDownloadManagerFileFragmentInfo::Test),
> val));
> I can get the above snippet to compile when the container holds
> regular pointers e.g.
> std::vector<CSwarmDownloadManagerFileFragmentInfo*> testVec;
> However, I am using boost::shared_ptr. According to the docs at
>, the boost replacement for mem_fun, mem_fn will work with
> shared_ptr's, but I cannot get it to work in either VC++6 or the new,
> supposedly more standard compliant VC++7.
> Here's my vector definition:
> std::vector<boost::shared_ptr<CSwarmDownloadManagerFileFragmentInfo> >
> testVec;
> I would appreciate help.

You need to use boost::bind. Replace the bind2nd() expression with:

boost::bind(&CSwarmDownloadManagerFileFragmentInfo::Test, _1, val)

mem_fn works with shared_ptr's, but bind2nd doesn't know this. ;-)

Boost list run by bdawes at, gregod at, cpdaniel at, john at