boost::lambda::bind

B

Barry Ding

#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>

using namespace std;
using namespace boost::lambda;

struct A {
A(int i) : i(i) {}
void print() const {
cout << "A::print: " << i << endl;
}
int i;
};

int main()
{
list<A> List;
List.push_back(A(1));
List.push_back(A(2));
List.push_back(A(3));
List.push_back(A(4));
for_each(List.begin(), List.end(), cout << bind(&A::i, _1) << '
'); // works

map<char const*, int> Map;
Map["hello"] = 10;
Map["world"] = 11;
for_each(Map.begin(), Map.end(),
cout << bind(&(pair<char const*, int>::first), _1)
//illegal reference to non-static member
//'std::pair<_Ty1,_Ty2>::first'
<< ' '
<< bind(&(pair<char const*, int>::second), _1)
);

return 0;
}
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top