I now have this code:
bool isAnyTrue() {
for(std::list< boost::shared_ptr<Foo> >::iterator i = mylist.begin(); i != mylist.end(); ++i) {
if( (*i)->isTrue() )
return true;
}
return false;
}
I used Boost here and then, but I couldn’t remember any simple way to write it, as if I could write it in Python, for example:
def isAnyTrue():
return any(o.isTrue() for o in mylist)
Is there any construct in STL / Boost to write it more or less like this?
Or maybe the equivalent of this Python code:
def isAnyTrue():
return any(map(mylist, lambda o: o.isTrue()))
Basically I am wondering if there is still an existing equivalent any(s all) in Boost / STL. Or why not (because it seems quite useful, and I use it quite often in Python).
source
share