class template
std::equal_to
<functional>
template <class T> struct equal_to;
Function object class for equality comparison
This class defines function objects for the equality comparison operation.
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 regular function call, and therefore it can be used in templates instead of a pointer to a function.
equal_to has its
operator() member defined such that it returns
true if its two arguments compare equal to each other using
operator==, and
false otherwise.
This class is derived from
binary_function and is defined as:
1 2 3 4
|
template <class T> struct equal_to : binary_function <T,T,bool> {
bool operator() (const T& x, const T& y) const
{return x==y;}
};
|
Objects of this class can be used with some standard algorithms such as
mismatch,
search or
unique.
Members
- bool operator() (const T& x, const T& y)
- Member function returning the result of the comparison x==y.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
// equal_to example
#include <iostream>
#include <utility>
#include <functional>
#include <algorithm>
using namespace std;
int main () {
pair<int*,int*> ptiter;
int foo[]={10,20,30,40,50};
int bar[]={10,20,40,80,160};
ptiter=mismatch ( foo, foo+5, bar, equal_to<int>() );
cout << "First mistmatching pair is: " << *ptiter.first;
cout << " and " << *ptiter.second << endl;
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)