boost::lmbda::bind

B

Barry Ding

#include <map>
#include <utility>
#include <algorithm>
#include <iostream>
#include <list>

#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) << '
');

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) //
#include <map>
#include <utility>
#include <algorithm>
#include <iostream>
#include <list>

#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) << '
');

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) //
same
);

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top