boost lambda question

N

nandor.sieben

Let m be of type vector<vector<int> >. I am trying to sort each
element of m:

for_each(m.begin(), m.end(), bind(sort, *_1.begin(), *_1.end());

This does not work:

'const struct
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >' has no
member named 'begin'

'const struct
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >' has no
member named 'end'

What do I do wrong?
 
E

Eric.Malenfant

Let m be of type vector<vector<int> >. I am trying to sort each
element of m:

for_each(m.begin(), m.end(), bind(sort, *_1.begin(), *_1.end());

This does not work:

Boost.Lambda does its magic by overloading operators. However, the
"dot" operator cannot be overloaded:
http://www.boost.org/doc/html/lambda/le_in_details.html#lambda.operator_expressions
So, to create a lambda invoking a member function, you have to use
bind expressions:
http://www.boost.org/doc/html/lambda/le_in_details.html#lambda.bind_expressions
Which makes the expression less elegant : What you want to express as:
_1.begin()
becomes something like:
bind(&std::vector<int>::begin, _1)

HTH,
Éric Malenfant
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top