Boost logo

Boost :

From: beatlebum1967 (beatlebum1967_at_[hidden])
Date: 2002-02-03 02:37:43


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. I get the following compiler errors:

c:\Program Files\Microsoft Visual Studio
.NET\Vc7\include\algorithm(21) : error C2664: 'std::binder2nd<class
boost::_mfi::mf1<int,class CSwarmDownloadManagerFileFragmentInfo,int>
>::operator`()'' : cannot convert parameter 1 from
'boost::shared_ptr<T>' to 'const std::binder2nd<_Fn2>::argument_type &
'
        with
        [
            T=CSwarmDownloadManagerFileFragmentInfo
        ]
        and
        [

_Fn2=boost::_mfi::mf1<int,CSwarmDownloadManagerFileFragmentInfo,int>
        ]
        Reason: cannot convert from 'boost::shared_ptr<T>' to 'const
std::binder2nd<_Fn2>::argument_type'
        with
        [
            T=CSwarmDownloadManagerFileFragmentInfo
        ]
        and
        [

_Fn2=boost::_mfi::mf1<int,CSwarmDownloadManagerFileFragmentInfo,int>
        ]
        No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
        c:\PROJECTS\vcpp\gjoob_shell_VC7\SwarmDownload.cpp(1002) : see
reference to function template instantiation '_Fn1
std::for_each
(_InIt,std::vector<_Ty,_Ax>::iterator,std::binder2nd<_Fn2>)'
being compiled
        with
        [

_Fn1=std::binder2nd<boost::_mfi::mf1<int,CSwarmDownloadManagerFileFrag
mentInfo,int>>,

_InIt=std::vector<boost::shared_ptr<CSwarmDownloadManagerFileFragmentI
nfo>,std::allocator<boost::shared_ptr<CSwarmDownloadManagerFileFragmen
tInfo>>>::iterator,

_Ty=boost::shared_ptr<CSwarmDownloadManagerFileFragmentInfo>,

_Ax=std::allocator<boost::shared_ptr<CSwarmDownloadManagerFileFragment
Info>>,

_Fn2=boost::_mfi::mf1<int,CSwarmDownloadManagerFileFragmentInfo,int>
        ]
c:\Program Files\Microsoft Visual Studio
.NET\Vc7\include\algorithm(21) : error C2064: term does not evaluate
to a function


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