#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
int main()
{
vector<bool> vectorObject;
int i;
for(i = 1; i < 10; i++)
vectorObject.push_back((bool)(i % 2));
cout << boolalpha; // turn on boolalpha I/O flag
cout << "Original contents of vectorObject:";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[ i ] << " ";
cout << endl;
// use the logical_not function object
transform(vectorObject.begin(), vectorObject.end(), vectorObject.begin(), logical_not<bool>());
cout << "Inverted contents of vectorObject:";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[ i ] << " ";
cout << endl;
return 0;
}
|