Question on boost lambda

  • Thread starter anton.bredikhin
  • Start date
A

anton.bredikhin

Hello everybody.

I want to write an unnamed predicate for std::find_if in-place.
If the vector is filled by raw struct, then I can find the target
element like that:


struct C
{
int i;
float f;
}

int main()
{
std::vector<C> v;
// somehow init v

std::find_if(v.begin(), v.end(), &_1->*&C::i == 3);
}


But I cannot make that to work if vector contains boost::shared_ptr to
the C struct.
std::vector<boost::shared_ptr<C> > v;
// somehow init v

std::find_if(v.begin(), v.end(), ???);

Can anyone tell me how can I achieve that?

Thanks
std::find_if(v.begin(), v.end(), /*v->i==3*/ ??)

If the vector is filled by structs without shared_ptr, then I can find
an element like that:

std::find_if(v.begin(), v.end(), &_1->*&C::i == 3);

But I cannot make that code to work with pointers.

Thanks
 
K

Kai-Uwe Bux

Hello everybody.

I want to write an unnamed predicate for std::find_if in-place.
If the vector is filled by raw struct, then I can find the target
element like that:


struct C
{
int i;
float f;
}

int main()
{
std::vector<C> v;
// somehow init v

std::find_if(v.begin(), v.end(), &_1->*&C::i == 3);
}


But I cannot make that to work if vector contains boost::shared_ptr to
the C struct.
std::vector<boost::shared_ptr<C> > v;
// somehow init v

std::find_if(v.begin(), v.end(), ???);
[snip]

Try: &*_1->*&C::i == 3


Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top