Boost logo

Boost Users :

From: Pete Hodgson (spam_at_[hidden])
Date: 2006-07-04 13:55:58


Hi All,

I'm just getting into using boost and stl algorithms, and I'm getting
some indecipherable compiler errors that I'd like some help understanding.

Here's some sample code:

<------------------------SNIP------------------------>

#include <boost/shared_ptr.hpp>
#include <boost/functional.hpp>
#include <boost/bind.hpp>

class CEgg
{
public:
        bool IsHatched() const;
};
typedef std::vector< boost::shared_ptr<CEgg> > tEggsVector;

//this function compiles with no problems
bool SomeEggsHaveHatched()
{
        tEggsVector basketOfEggs;

        tEggsVector::const_iterator it = std::find_if(
                basketOfEggs.begin(),
                basketOfEggs.end(),
                boost::mem_fn( &CEgg::IsHatched ) );

        bool bSomeEggsHaveHatched = ( it != basketOfEggs.end() );
        return bSomeEggsHaveHatched;
}

//this function doesn't compile,
//presumably because of the boost::not1 usage
bool AllEggsHaveHatched()
{
        tEggsVector basketOfEggs;

        tEggsVector::iterator it = std::find_if(
                basketOfEggs.begin(),
                basketOfEggs.end(),
                boost::not1( boost::mem_fn( &CEgg::IsHatched ) ) );

        bool bSomeEggsHaventHatched = ( it != basketOfEggs.end() );
        return !bSomeEggsHaventHatched;
}
<------------------------SNIP------------------------>

When I try and compile this in Visual C++ 2003 I get the following
compile errors for AllEggsHaveHatched():

c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\algorithm(64) : error C2664: 'bool
boost::unary_negate<Predicate>::operator ()(const
boost::call_traits<T>::param_type) const' : cannot convert parameter 1
from 'std::allocator<_Ty>::value_type' to 'const
boost::call_traits<T>::param_type'
         with
         [
             Predicate=boost::_mfi::cmf0<bool,CEgg>,
 
T=boost::unary_traits<boost::_mfi::cmf0<bool,CEgg>>::argument_type
         ]
         and
         [
             _Ty=boost::shared_ptr<CEgg>
         ]
         and
         [
 
T=boost::unary_traits<boost::_mfi::cmf0<bool,CEgg>>::argument_type
         ]
         No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
         c:\WORK\4DCapture_Soln\VideoCapture\PixelinkCaptureFacade.h(46)
: see reference to function template instantiation '_InIt
std::find_if<std::vector<_Ty>::iterator,boost::unary_negate<Predicate>>(_InIt,_InIt,_Pr)'
being compiled
         with
         [
             _InIt=std::vector<boost::shared_ptr<CEgg>>::iterator,
             _Ty=boost::shared_ptr<CEgg>,
             Predicate=boost::_mfi::cmf0<bool,CEgg>,
             _Pr=boost::unary_negate<boost::_mfi::cmf0<bool,CEgg>>
         ]

Any idea why boost::not1 seems to be causing problems? Should I be using
std::not1? or boost::mem_fun instead of boost:mem_fn?

Cheers and TIA,

Pete


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