1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <boost/bind.hpp>
using namespace std;
class Foo
{
public:
Foo(int val) : m_val(val) {}
bool operator==(const Foo & foo) const { return (foo.m_val == m_val); }
private:
int m_val;
};
bool same_as(const Foo & val1, const Foo & val2)
{
return (val1 == val2);
}
int main()
{
vector<Foo> vf;
vf.push_back(Foo(1));
vf.push_back(Foo(2));
vf.push_back(Foo(3));
vf.push_back(Foo(4));
vf.push_back(Foo(5));
typedef vector<Foo>::const_iterator VI;
VI p = find_if(vf.begin(), vf.end(), boost::bind( same_as, _1, Foo(3) ));
cout << ((p != vf.end()) ? "OUI" : "NON") << endl;
return 0;
} |