I am using the std::partition to split a vector in two sub vectors. I want to know if the first partition is empty
#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';
}
How to check if the non zeros partition contains elements or not?
bound == v.begin() when first partition is empty.bound == v.end() when second partition is empty.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With