Boost logo

Boost Users :

From: Gianluca Silvestri (gianluca.silvestri_at_[hidden])
Date: 2003-10-31 09:03:23


> -----Messaggio originale-----
> Da: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] Per conto di Darren Cook
> Inviato: venerd́ 31 ottobre 2003 14.31
> A: Boost Users mailing list
> Oggetto: Re: [Boost-users] [BLL] How to search in a list for
> an objectcomparinga data member?
>
>
> >>struct Foo { int fDataMember;}
> >>
> >>int main()
> >>{
> >> std::vector<Foo> foos;
> >> Foo fo;
> >> std::find_if(foos.begin(), foos.end(), _1->fDataMember ==
> >>fo.fDataMember); //<-- won't compile; }
>
> As your vector is of Foo, not Foo*, did you mean "_1.fDataMember" ?
>
> If so, you can do this:
> std::find_if(foos.begin(), foos.end(),
> bind(&Foo::fDataMember,_1) == fo.fDataMember);
>
> That assumes:
> #include <boost/lambda/lambda.hpp>
> #include <boost/lambda/bind.hpp>
> using namespace boost::lambda;
>
> > I imagine you're having trouble with "_1->fDataMember".
>
> I didn't realize there was a limitation when using "->".
> Surely there must
> already be something in the lambda library to deal with this?
> It seems like
> something that must come up a lot.
>
> Darren

Thanks
Gianluca
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/bo> ost-users
>


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