jeudi 15 juillet 2021

Is there something like std::any_of that will apply predicate to all elements

The behavior of std::any_of function template is equivalent to:

 template<class InputIterator, class UnaryPredicate>   bool any_of
 (InputIterator first, InputIterator last, UnaryPredicate pred) {  
 while (first!=last) {
     if (pred(*first)) return true;
     ++first;   }   return false; }

So it won't apply predicate to all elements. is there some other function that return true if any of the elements return true for this predicate, but in the same time t will run the predicate for all elements from the given range?

UPD: so for why I need that - my function modify element of the container by certain rule and return true of element was modified and false otherwise. So I need to know if any of the elements was modified

Aucun commentaire:

Enregistrer un commentaire