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

std::

equal_to

类模板  <functional>

template <class T> struct equal_to;

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

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

它的行为定义如下:

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


该类的对象可用于标准算法,如transform或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)。

☣  示例



// equal_to example
#include <iostream>     // std::cout
#include <utility>      // std::pair
#include <functional>   // std::equal_to
#include <algorithm>    // std::mismatch

int main () {
  std::pair<int*,int*> ptiter;
  int foo[]={10,20,30,40,50};
  int bar[]={10,20,40,80,160};
  ptiter = std::mismatch (foo, foo+5, bar, std::equal_to<int>());
  std::cout << "First mismatching pair is: " << *ptiter.first;
  std::cout << " and " << *ptiter.second << '\n';
  return 0;
}

输出:
First mismatching pair is: 30 and 40

🍄  另请参阅



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

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