Algorithms for the properties of test sequences of generic algorithm (iii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.