This C++ program demonstrates the binary negater with equal_to predicate. The program creates two vectors and lexicographically compares the two vectors using negated version of equal_to as a predicate. This results in an inverse effect without negation.
Here is the source code of the C++ program which demonstrates the binary negater with equal_to predicate. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to use negater with binary equal_to predicate
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <iomanip>
using namespace std;
void print(int a[], int N)
{
for(int i = 0; i < N; i++)
{
cout << setw(2) << a[i] << " ";
}
cout << endl;
}
int main()
{
int arr1[] = {0, 1, 2, 4, 8, 16, 32};
int arr2[] = {0, 1, 2, 4, 8, 16, 32, 64};
bool result;
cout << "arr1 : ";
print(arr1, 7);
cout << "arr2 : ";
print(arr2, 8);
// Comparing a and b lexicographically
cout << "Comparing using negater with equal_to predicate"
<< endl;
result = lexicographical_compare(arr1, arr1 + 7, arr2 , arr2 + 8, not2(equal_to<int>()));
if(result == true)
{
cout << "arr1 is lexicographically is not equal to arr2."
<< endl;
}
else
{
cout << "a is lexicographically equal to b."
<< endl;
}
}
$ a.out arr1 : 0 1 2 4 8 16 32 arr2 : 0 1 2 4 8 16 32 64 Comparing using negater with equal_to predicate arr1 is lexicographically is not equal to arr2.
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Related Posts:
- Apply for Information Technology Internship
- Apply for Computer Science Internship
- Apply for C++ Internship
- Practice Programming MCQs
- Check C++ Books