Boost logo

Boost Users :

From: Tom Matelich (tmatelich_at_[hidden])
Date: 2002-08-09 17:40:15


> -----Original Message-----
> From: Douglas Gregor [mailto:gregod_at_[hidden]]
> Sent: Friday, August 09, 2002 3:32 PM
> To: Boost-Users_at_[hidden]
> Subject: Re: [Boost-Users] Getting the hang of Boost::Bind
>
>
> On Friday 09 August 2002 06:08 pm, Tom Matelich wrote:
> > I have a vector of
> >
> > class Landmark
> > {
> > public:
> > std::string const& getName() const;
> > ...
> > };
> >
> > I want to do a find_if for a name that I have.
> >
> > something like
> > std::find_if(begin, end, boost::bind(std::equal<std::string>(???,
> > name_to_find)));
> >
> > What do I put for the ??? ?
>
> I presume that [begin, end) is an iterator sequence of
> Landmark instances?
> Then ??? = boost::bind(&Landmark::getName, _1), meaning that
> the first
> parameter to std::equal<std::string>::operator() is a call to
> Landmark::getName where the object parameter (this) is the
> first argument
> (_1) to the bind function object.
 
Thanks for the quick reply. That's what I thought. To make things more
concrete...

std::vector<Landmark> v;
...
std::vector<Landmark>::const_iterator iter =
   std::find_if(v.begin(), v.end(),
                boost::bind(std::equal<std::string>,
                            boost::bind(ZLandmark::Landmark::getName, _1),
                            name_to_find));

Is what I think you're telling me. Perhaps I should mention now that I am
using VC6. Compiling the above line I get many errors, here are the first
three:

inspdoc.cpp(453) : error C2780: 'class boost::_bi::bind_t<R,class
boost::_mfi::dm<R,T>,class boost::_bi::list1<class boost::_bi::value<R> > >
__cdecl boost::bind(R T::*,A1)' : expects 2 arguments -
 3 provided
        c:\dev\opt\include\boost/bind.hpp(1362) : see declaration of 'bind'
inspdoc.cpp(453) : error C2780: 'class boost::_bi::bind_t<R,struct
boost::_mfi::cmf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,class boost::_bi::list9<class
boost::_bi::value<R>,class boost::_bi::value<R>,class
 boost::_bi::value<R>,class boost::_bi::value<R>,class
boost::_bi::value<R>,class boost::_bi::value<R>,class
boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> >
> __cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6,B7,
B8) const,A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 10 arguments - 3 provided
        c:\dev\opt\include\boost/bind/bind_mf_cc.hpp(223) : see declaration
of 'bind'
inspdoc.cpp(453) : error C2780: 'class boost::_bi::bind_t<R,struct
boost::_mfi::mf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,class boost::_bi::list9<class
boost::_bi::value<R>,class boost::_bi::value<R>,class
boost::_bi::value<R>,class boost::_bi::value<R>,class
boost::_bi::value<R>,class boost::_bi::value<R>,class
boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> >
> __cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6,B7,B
8),A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 10 arguments - 3 provided
        c:\dev\opt\include\boost/bind/bind_mf_cc.hpp(212) : see declaration
of 'bind'

Oh, and I guess that should be std::equal_to, right? Didn't work either
though.

Thanks,
Tom

PS Unfortunately, I have to run. I'll be looking at this again this weekend
though.

-----------------------------------------------------------------------
DISCLAIMER: Information contained in this message and/or
attachment(s) may contain confidential information of Zetec, Inc.
If you have received this transmission in error, please notify
the sender by return email.
-----------------------------------------------------------------------


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