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

std::

not2

类模板  <functional>

template <class Predicate>
  binary_negate<Predicate> not2 (const Predicate& pred);

返回二元函数对象的结果相反的二元函数对象
构造一个二元函数对象(binary_negate类型),返回与pred相反的值(与operator !返回的值相同)。

它的行为定义如下:
template <class Predicate> binary_negate<Predicate> not2 (const Predicate& pred)
{
  return binary_negate<Predicate>(pred);
}

☲  参数


pred
派生自binary_function的二元函数对象。

☉  返回值



与pred行为相反的二元函数对象。
参阅binary_negate。

☣  示例



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

int main () {
  int foo[] = {10,20,30,40,50};
  int bar[] = {0,15,30,45,60};
  std::pair<int*,int*> firstmatch,firstmismatch;
  firstmismatch = std::mismatch (foo, foo+5, bar, std::equal_to<int>());
  firstmatch = std::mismatch (foo, foo+5, bar, std::not2(std::equal_to<int>()));
  std::cout << "First mismatch in bar is " << *firstmismatch.second << '\n';
  std::cout << "First match in bar is " << *firstmatch.second << '\n';
  return 0;
}

输出:
First mismatch in bar is 0
First match in bar is 30

🍄  另请参阅



not1 返回一元函数对象的结果相反的一元函数对象(类模板)
binary_function 二元函数对象基类 (类模板)

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