Hi,
im failing with my first try to use unary_function, i got something (which i partly borrowed from another forum):
which works, but when i comment in the 'doit' part the compiler complains, that condition(a[i]) does not evaluate to a function ....
i suppose its a trivial error?! anybody?
im failing with my first try to use unary_function, i got something (which i partly borrowed from another forum):
Code:
#include <algorithm> #include <functional> #include <iostream> using namespace std; template <typename T> class is_good : public std::unary_function<T, bool> { public: is_good(const T & arg) : _val(arg) { } ~is_good() { } bool operator()(const T p) const { return p == _val; } private: T _val; }; //int doit ( // const int* a, // unsigned int size, // std::unary_function< int, bool > condition ) //{ // int sum = 0; // for ( unsigned int i =0 ; i < size; ++i ) // { // if ( condition(a[i]) ) // sum += a[i]; // } // return sum; //} void main() { int a[10] = {4, 9, 5, 6, 9, 10, 9, 255, 60, 0}; int* x = std::find_if(a, a+10, is_good<int>(10)); //doit( a, 10, is_good<int>(12) ); }
i suppose its a trivial error?! anybody?
Comment