Boost logo

Boost :

From: beatlebum1967 (beatlebum1967_at_[hidden])
Date: 2002-02-04 14:02:11


--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> From: "beatlebum1967" <beatlebum1967_at_y...>
> > 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
> > boost.org, 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. ;-)

Thanks buddy! One question though, I could get the passed parameter
to work with methods that expect references. Is there something else
I need to do in this case?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk