I'm wondering whether it is possible to somehow extract current iteration number from c++11 foreach statement.
In code like this:
for(auto &i: vect)
if(i == 0) zero_value_index = /* here I want my index */;
I can't find another way around, but using old-fashioned for
with int i
to easily obtain my index.
Ideas?
You could, I don't know, count the iterations:
int i = 0;
for (auto& el : container) {
if (el == 0) zero_value_index = i;
++i;
}
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