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

std::

not1

类模板  <functional>

template <class Predicate>
  unary_negate<Predicate> not1 (const Predicate& pred);

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

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

☲  参数


pred
定义了成员argument_type的类类型一元函数对象。

☉  返回值



与pred行为相反的一元函数对象。
参阅unary_negate。

☣  示例



// not1 example
#include <iostream>     // std::cout
#include <functional>   // std::not1
#include <algorithm>    // std::count_if

struct IsOdd {
  bool operator() (const int& x) const {return x%2==1;}
  typedef int argument_type;
};

int main () {
  int values[] = {1,2,3,4,5};
  int cx = std::count_if (values, values+5, std::not1(IsOdd()));
  std::cout << "There are " << cx << " elements with even values.\n";
  return 0;
}

输出:
There are 2 elements with even values.

🍄  另请参阅



not2 返回二元函数对象的结果相反的二元函数对象(类模板)
unary_negate 对一元函数对象求反的类(类模板)

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