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

std::

not_equal_to

类模板  <functional>

template <class T> struct not_equal_to;

用于不相等比较的函数对象类
二元函数对象类,其调用将返回两个参数比较是否不相等(由运算符 !=返回)。

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

它的行为定义如下:

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


该类的对象可用于 mismatch, search或unique等标准算法。

☲  模板参数


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)。

☣  示例



// not_equal_to example
#include <iostream>     // std::cout
#include <functional>   // std::not_equal_to
#include <algorithm>    // std::adjacent_find

int main () {
  int numbers[]={10,10,10,20,20};
  int* pt = std::adjacent_find (numbers, numbers+5, std::not_equal_to<int>()) +1;
  std::cout << "The first different element is " << *pt << '\n';
  return 0;
}

输出:
The first different element is 20

🍄  另请参阅



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

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