class template
<functional>

std::not_equal_to

template <class T> struct not_equal_to;
Function object class for non-equality comparison
Binary function object class whose call returns whether its two arguments compare not equal (as returned by operator operator!=).

Generically, function objects are instances of a class with member function operator() defined. This member function allows the object to be used with the same syntax as a function call.

It is defined with the same behavior as:

1
2
3
template <class T> struct not_equal_to : binary_function <T,T,bool> {
  bool operator() (const T& x, const T& y) const {return x!=y;}
};
1
2
3
4
5
6
template <class T> struct not_equal_to {
  bool operator() (const T& x, const T& y) const {return x!=y;}
  typedef T first_argument_type;
  typedef T second_argument_type;
  typedef bool result_type;
};

Objects of this class can be used on standard algorithms such as mismatch, search or unique.

Template parameters

T
Type of the arguments to compare by the functional call.
The type shall support the operation (operator!=).

Member types

member typedefinitionnotes
first_argument_typeTType of the first argument in member operator()
second_argument_typeTType of the second argument in member operator()
result_typeboolType returned by member operator()

Member functions

bool operator() (const T& x, const T& y)
Member function returning whether the arguments compare not equal (x!=y).

Example

1
2
3
4
5
6
7
8
9
10
11
// 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;
}

Output:

The first different element is 20


See also