I am trying to use the any_of function for bool's vector. The any_of function requires a unary predicate function that returns a bool. However, I cannot figure out what to use when the value entered into the function is already the bool that I want. I would suggest some kind of function name, such as "logical_true" or "istrue" or "if", but none of them work. I pasted the code below to show what I'm trying to do. Thanks in advance for any ideas. --Chris
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
vector<bool>testVec(2);
testVec[0] = true;
testVec[1] = false;
bool anyValid;
anyValid = std::find(testVec.begin(), testVec.end(), true) != testVec.end();
cout << "anyValid = " << anyValid <<endl;
return 0;
}
source
share