首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::partition_point

Defined in header <algorithm>

?

?

template< class ForwardIt, class UnaryPredicate > ForwardIt partition_point( ForwardIt first, ForwardIt last, UnaryPredicate p );

(1)

(since C++11)

检查分区%28,如果std::partition%29范围[first, last)并定位第一个分区的末尾,即不满足的第一个元素。plast如果所有元素都满足p...

参数

first, last

-

the partitioned range of elements to examine

p

-

unary predicate which returns ?true for the elements found in the beginning of the range. The signature of the predicate function should be equivalent to the following: bool pred(const Type &a); The signature does not need to have const &, but the function must not modify the objects passed to it. The type Type must be such that an object of type ForwardIt can be dereferenced and then implicitly converted to Type. ?

类型要求

---。

-单数预测必须满足谓词的要求。

返回值

中的第一个分区结束后的迭代器。[first, last)last如果所有元素都满足p...

复杂性

O%28 log%28N%29%29,其中N =std::distance(first, last),谓词p的应用。

二次

代码语言:javascript
复制
#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
 
int main()
{
    std::array<int, 9> v = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
 
    auto is_even = [](int i){ return i % 2 == 0; };
    std::partition(v.begin(), v.end(), is_even);
 
    auto p = std::partition_point(v.begin(), v.end(), is_even);
 
    std::cout << "Before partition:\n    ";
    std::copy(v.begin(), p, std::ostream_iterator<int>(std::cout, " "));
    std::cout << "\nAfter partition:\n    ";
    std::copy(p, v.end(), std::ostream_iterator<int>(std::cout, " "));
}

二次

产出:

二次

代码语言:javascript
复制
Before partition:
    8 2 6 4 
After partition:
    5 3 7 1 9

二次

另见

is_sorted (C++11)

checks whether a range is sorted into ascending order (function template)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com