function template
<functional>

std::not2

template <class Predicate>  binary_negate<Predicate> not2 (const Predicate& pred);
返回二元函式物件的否定
構造一個二元函式物件(型別為 binary_negate),該物件返回 pred 的相反值(透過 operator ! 返回)。

它的定義與以下行為相同:
1
2
3
4
template <class Predicate> binary_negate<Predicate> not2 (const Predicate& pred)
{
  return binary_negate<Predicate>(pred);
}

引數

謂詞
派生自 binary_function 的二進位制函式物件。

返回值

一個行為與 pred 相反的二元函式物件。
參見 binary_negate

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 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


另見