title: Access index in range-for loop
body: <p>I have a vector of objects and am iterating through it using a range-for loop. I am using it  to print a function from the object, like this:</p>
  
  <pre><code>vector&lt;thisObject&gt; storedValues;
  //put stuff in storedValues
  for(auto i:storedValues)
  {
     cout&lt;&lt;i.function();
  }
  </code></pre>
  
  <p>But I want to print the index too. My desired output is: </p>
  
  <pre><code>1: value
  2: value
  //etc
  </code></pre>
  
  <p>I was going to just use a counter that I increased each time, but that seemed very inefficient. Is there a better way?</p>