[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Question on boost lambda

anton.bredikhin

11/7/2008 1:58:00 PM

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
2 Answers

Kai-Uwe Bux

11/7/2008 2:45:00 PM

0

anton.bredikhin@gmail.com wrote:

> 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

anton.bredikhin

11/7/2008 3:18:00 PM

0

> Try:  &*_1->*&C::i == 3
>
> Best
>
> Kai-Uwe Bux

It works!
Thanks a lot!