1, all_of (inputiterator First, Inputiterator last, Unarypredicate pred): C11 algorithm. Returns true if all elements of the sequence satisfy the predicate pred
For example, determine whether the elements in a sequence are less than 0:
std::vector<int>C; //add element { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1} for(inti =0; I <Ten; i++) {C.push_back (i-Ten); } //returns True BOOLresult = Std::all_of (C.begin (), C.end (), [] (intElement) { returnElement <0; }); Std::cout<< (int) result;
Printed results: 1
2, Any_of (inputiterator First, Inputiterator last, Unarypredicate pred): C11 algorithm. Returns true if the sequence exists where the element satisfies the predicate pred
std::vector<int>C; //add element { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1} for(inti =0; I <Ten; i++) {C.push_back (i-Ten); } //returns True because -10<-9 exists BOOLresult = Std::any_of (C.begin (), C.end (), [] (intElement) { returnElement <-9; }); Std::cout<< (int) result;
Printed results: 1
3, None_of (inputiterator First, Inputiterator last, Unarypredicate pred): C11 algorithm. Returns true if all elements in the sequence do not satisfy the predicate pred
std::vector<int>C; //add element { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1} for(inti =0; I <Ten; i++) {C.push_back (i-Ten); } //returns True because there is no element greater than 0 BOOLresult = Std::none_of (C.begin (), C.end (), [] (intElement) { returnElement >0; }); Std::cout<< (int) result; //Printed results: 1
Algorithms for the properties of test sequences of generic algorithm (iii)