class template
<functional>
std::equal_to
template <class T> struct equal_to;
Function object class for equality comparison
Binary function object class whose call returns whether its two arguments compare equal (as returned by 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:
| 12
 3
 
 | template <class T> struct equal_to : binary_function <T,T,bool> {
  bool operator() (const T& x, const T& y) const {return x==y;}
};
 | 
 
| 12
 3
 4
 5
 6
 
 | template <class T> struct 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 type | definition | notes | 
|---|
| first_argument_type | T | Type of the first argument in member operator() | 
| second_argument_type | T | Type of the second argument in member operator() | 
| result_type | bool | Type returned by member operator() | 
Member functions
- bool operator() (const T& x, const T& y)
- Member function returning whether the arguments compare equal (x==y).
Example
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 
 | // 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;
}
 | 
Output:
| 
First mismatching pair is: 30 and 40
 | 
See also
- not_equal_to
- Function object class for non-equality comparison (class template
)
- greater
- Function object class for greater-than inequality comparison (class template
)
- less
- Function object class for less-than inequality comparison (class template
)
- greater_equal
- Function object class for greater-than-or-equal-to comparison (class template
)
- less_equal
- Function object class for less-than-or-equal-to comparison (class template
)
- binary_function
- Binary function object base class (class template
)