Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

greater_equal

类模板  <functional>

template <class T> struct greater_equal;

用于大于等于比较的函数对象类
二元函数对象类,其调用将返回其第一个参数的比较是否大于或等于第二个参数(由操作符>=返回)。

一般来说,函数对象是定义了成员函数operator()的类的实例。该成员函数允许使用与函数调用相同的语法来使用对象。

它的行为定义如下:

C++98
template <class T> struct greater_equal : binary_function <T,T,bool> {
  bool operator() (const T& x, const T& y) const {return x>=y;}
};


该类的对象可用于sort, merge 或 lower_bound等标准算法。

☲  模板参数


T
函数调用要比较的参数的类型。
类型应支持操作(operator>=)。

☲  成员类型


成员类型 定义 注释
first_argument_type T 成员operator()中第一个参数的类型
second_argument_type T 成员operator()中第二个参数的类型
result_type bool 成员operator()返回的类型

☲  成员函数



T operator() (const T& x, const T& y)
成员函数,返回第一个参数比较是否大于或等于第二个参数(x>=y).

☣  示例



// 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.

🍄  另请参阅



equal_to 用于相等比较的函数对象类(类模板)
not_equal_to 用于非相等比较的函数对象类(类模板)
greater 用于大于不等比较的函数对象类(类模板)
less 用于小于不等比较的函数对象类(类模板)
less_equal 用于小于等于比较的函数对象类(类模板)
binary_function 二元函数对象基类 (类模板)

联系我们 免责声明 关于CandCplus 网站地图