Hello!
Consider following example:
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <boost/bind.hpp>
const int num = 3;
class foo {
private:
int x;
public:
foo(): x(0) {}
foo(int xx): x(xx) {}
~foo() {}
bool is_equal(int xx) const {
return (x == xx);
}
void print() {
std::cout << "x = " << x << std::endl;
}
};
typedef std::vector<foo> foo_vect;
int
main() {
foo_vect fvect;
for (int i = -num; i < num; i++) {
fvect.push_back(foo(i));
}
foo_vect::iterator found;
found = std::find_if(fvect.begin(), fvect.end(),
boost::bind(&foo::is_equal, _1, 0));
if (found != fvect.end()) {
found->print();
}
return 0;
}
Is there a way to use some sort of negator adaptor with foo::is_equal()
to find first non zero element. I don't want to write foo::is_not_equal(int)
method, I believe there is a better way. I tried to play with std::not2
, but without success.