std::partition_point
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <algorithm> 中定义
|
||
template< class ForwardIt, class UnaryPredicate > ForwardIt partition_point( ForwardIt first, ForwardIt last, UnaryPredicate p); |
(1) | (C++11 起) |
查看分区(如果std::partition)范围内
[first, last)
和定位的第一个分区的结束,也就是不符合的第一个元素p
或last
如果最后,如果所有的元素满足p
.原文:
Examines the partitioned (as if by std::partition) range
[first, last)
and locates the end of the first partition, that is, the first element that does not satisfy p
or last
if last if all elements satisfy 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. |
类型要求 | ||
-ForwardIt 必须满足 ForwardIterator 的要求。
|
[编辑] 返回值
过去的迭代器
[first, last)
或last
的第一个分区内所有元素是否满足p
.原文:
The iterator past the end of the first partition within
[first, last)
or last
if all elements satisfy p
.[编辑] 复杂度
first
和last
之间的距离在对数原文:
Logarithmic in the distance between
first
and last
[编辑] 示例
#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, " ")); }
输出:
Before partition: 8 2 6 4 After partition: 5 3 7 1 9
[编辑] 另请参阅
(C++11) |
检查区间是否按升序排列 (函数模板) |