std::stable_partition
来自cppreference.com
|
|
该页由英文版维基使用谷歌翻译机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击此处。 |
<metanoindex/>
| 在标头 <algorithm> 定义
|
||
| |
||
重新排序的范围
[first, last)在这样一种方式中的元素,所有元素的谓词p回报true之前的元素为谓词p回报false。元素的相对顺序被保存. 参数
| first, last | - | |
| p | - | 如果该元素的,要责令之前的其他元素 则返回 true 的一元谓词。对每个(可为 const 的) |
| 类型要求 | ||
返回值
迭代器到第二组的第一个元素
复杂度
究竟
last-first应用程序的谓词和最(last-first)*log(last-first)掉期,如果有足够的内存或线性的掉期,如果有足够的可用内存.示例
运行此代码
#include <iostream>
#include <algorithm>
int main()
{
std::vector<int> v{0, 0, 3, 0, 2, 4, 5, 0, 7};
std::stable_partition(v.begin(), v.end(), [](int n){return n>0;});
for (int n : v) {
std::cout << n << ' ';
}
std::cout << '\n';
}
输出:
3 2 4 5 7 0 0 0 0
另请参阅
| 将范围中元素分为两组 (函数模板) |