title: Accessing a vector iterator by index?
body: <p>Recently I came across this code in my codebase (Simplified for here, of course)</p>
  
  <pre><code>auto toDelete = std::make_shared&lt;std::string&gt;("FooBar");
  std::vector&lt;decltype(toDelete)&gt; myVec{toDelete};
  auto iter = std::find_if(std::begin(myVec), std::end(myVec), 
     [](const decltype(toDelete) _next)
     {
        return *_next == "FooBar";
     });
  
  if (iter != std::end(myVec))
  {
     std::shared_ptr&lt;std::string&gt; deletedString = iter[0];
     std::cout &lt;&lt; *deletedString;
     myVec.erase(iter);
  }
  </code></pre>
  
  <p><a href="http://coliru.stacked-crooked.com/a/34b34c727341c25f" rel="nofollow">Online Example</a></p>
  
  <p>Now, I noticed that here we are accessing an iterator by indexing!</p>
  
  <pre><code>std::shared_ptr&lt;std::string&gt; deletedString = iter[0];
  </code></pre>
  
  <p>I've never seen anyone access an iterator by indexing before, so all I can guess at is that the iterator gets treated like a pointer, and then we access the first element pointed to at the pointer. So is that code actually equivalent to:</p>
  
  <pre><code>std::shared_ptr&lt;std::string&gt; deletedString = *iter;
  </code></pre>
  
  <p>Or is it Undefined Behavior?</p>