Currently, I can only do ranged based loops with this:
for (auto& value : values)
But sometimes I need an iterator to the value, instead of a reference (For whatever reason). Is there any method without having to go through the whole vector comparing values?
Use the old
forloop as:With this, you’ve
valueas well as iteratorit. Use whatever you want to use.EDIT:
Although I wouldn’t recommended this, but if you want to use range-based
forloop (yeah, For whatever reason :D), then you can do this:This approach avoids searching given
value, sincevalueanditare always in sync.