boost/lambda and structures

R

Rafal Dabrowa

Suppose I have the following structure:

struct xy { int x, y; };

and the following vector:

vector<xy> v(10);

I want to use boost/lambda for find an item in the table.
Let's say, with x member value equal to 10. I wrote
something like this:

vector<xy>::iterator pos = find_if(v.begin(), v.end(), _1.x == 10);

but this doesn't work. Compiler complains that 'const struct
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >' has no
member named 'x'.
How the above code should look correctly ?


Rafal
 
J

Jeff Flinn

Rafal said:
Suppose I have the following structure:

struct xy { int x, y; };

and the following vector:

vector<xy> v(10);

I want to use boost/lambda for find an item in the table.
Let's say, with x member value equal to 10. I wrote
something like this:

vector<xy>::iterator pos = find_if(v.begin(), v.end(), _1.x ==
10);
but this doesn't work. Compiler complains that 'const struct
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >' has no
member named 'x'.
How the above code should look correctly ?

You might want to join the boost user mailing list where your're more apt to
get more expert help. See www.boost.org. In the meantime, you may have to
use:

bind( &xy::x, _1 ) == 10

This should work. I'm not sure if there's a non-bind syntax that would work.

Jeff Flinn
 
R

Rafal Dabrowa

Jeff said:
You might want to join the boost user mailing list where your're more apt to
get more expert help. See www.boost.org. In the meantime, you may have to
use:

bind( &xy::x, _1 ) == 10

This should work. I'm not sure if there's a non-bind syntax that would work.

Thank you.


Rafal
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top