我正在使用 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';
}
Run Code Online (Sandbox Code Playgroud)
如何检查非零分区是否包含元素?