【发布时间】:2020-11-12 17:49:10
【问题描述】:
我正在使用 std::partition 将一个向量拆分为两个子向量。我想知道第一个分区是否为空
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main() {
vector<uint32_t> v {0,1,2,3,4,0,0,0};
auto bound = std::stable_partition(v.begin(), v.end(), [](auto element)
{
return element > 0;
});
// print out content:
std::cout << "non zeros";
for (auto it=v.begin(); it!=bound; ++it)
std::cout << ' ' << *it;
std::cout << '\n';
std::cout << "zeros";
for (auto it=bound; it!=v.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
}
如何检查非零分区是否包含元素?
【问题讨论】: