Boost logo

Boost Users :

From: Darren Cook (darren_at_[hidden])
Date: 2003-10-31 08:30:46

>>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.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at