By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,946 Members | 1,298 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,946 IT Pros & Developers. It's quick & easy.

Question on boost lambda

P: n/a
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<Cv;
// 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
Nov 7 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
an*************@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<Cv;
// 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
Nov 7 '08 #2

P: n/a
Try: *&*_1->*&C::i == 3
>
Best

Kai-Uwe Bux
It works!
Thanks a lot!
Nov 7 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.