boost的函数:is_partitioned

来源:互联网 发布:搜狐网络大厦地址 编辑:程序博客网 时间:2024/05/22 23:27
template <typename InputIterator, typename UnaryPredicate>bool is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p ){//  Run through the part that satisfy the predicate    for ( ; first != last; ++first )        if ( !p (*first))            break;//  Now the part that does not satisfy the predicate    for ( ; first != last; ++first )        if ( p (*first))            return false;    return true;}


功能描述:

容器区间内的元素是否以函数P进行划分;容器区间元素分为两部分,第一部分满足函数要求,第二部分不满足函数要求。


示例:

bool isOdd(int i) {return i % 2 == 1;}bool lessThan10(int i){return i < 10;}int myints[] = {0, 1, 2, 3, 14, 15};vector<int> c(myints,  myints + sizeof(myints) / sizeof(int) );is_partitioned ( c, isOdd ); //falseis_partitioned ( c, lessThan10 ); //trueis_partitioned ( c.begin (), c.end (), lessThan10 ); //trueis_partitioned ( c.begin (), c.begin () + 3, lessThan10 ); //trueis_partitioned ( c.end (), c.end (), isOdd ); //true:empty range


0 0
原创粉丝点击