template <class T> struct greater_equal;
123
template <class T> struct greater_equal : binary_function <T,T,bool> { bool operator() (const T& x, const T& y) const {return x>=y;} };
123456
template <class T> struct greater_equal { bool operator() (const T& x, const T& y) const {return x>=y;} typedef T first_argument_type; typedef T second_argument_type; typedef bool result_type; };
operator()
x>=y
1234567891011
// greater_equal example #include <iostream> // std::cout #include <functional> // std::greater_equal, std::bind2nd #include <algorithm> // std::count_if int main () { int numbers[]={20,-30,10,-40,0}; int cx = std::count_if (numbers, numbers+5, std::bind2nd(std::greater_equal<int>(),0)); std::cout << "There are " << cx << " non-negative elements.\n"; return 0; }
There are 3 non-negative elements.