C ++中的partition_point
在本教程中,我们将讨论一个了解C++中partition_point的程序。
分区点是一种返回迭代器的方法,该迭代器指向给定范围内的第一个值。该范围是一个分区,其中谓词不正确。
示例
#include <iostream>
#include <algorithm>
#include <vector>
bool IsOdd(int i) { return (i % 2) == 1; }
int main(){
std::vector<int> data{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::vector<int> odd, even;
std::stable_partition(data.begin(), data.end(), IsOdd);
auto it = std::partition_point(data.begin(), data.end(),
IsOdd);
odd.assign(data.begin(), it);
even.assign(it, data.end());
std::cout << "odd:";
for (int& x : odd)
std::cout << ' ' << x;
std::cout << '\n';
std::cout << "even:";
for (int& x : even)
std::cout << ' ' << x;
std::cout << '\n';
return 0;
}输出结果
odd: 1 3 5 7 9 even: 2 4 6 8 10
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短