title: How to construct a std::list iterator in loop with increment
body: <p>I'm trying to do a double-loop over a std::list to operate on each pair of elements. However, I'm having some trouble initialising the second iterator. The code I'd like to write is:</p>
  
  <pre><code>for(std::list&lt;int&gt;::iterator i = l.begin(); i != l.end(); ++i) {
      for(std::list&lt;int&gt;::iterator j = i+1; j != l.end(); ++j) {
          ...
      }
  }
  </code></pre>
  
  <p>That doesn't work because list iterators aren't random-access, so you can't do +1. But I'm having some trouble finding a neat alternative; the compiler doesn't seem to be very happy with <code>std::list&lt;int&gt;::iterator j(i)++;</code> which I had some hope for. Achieving what I want seems like I'm going to have to have some awkward extra increment which won't fit the structure of the for loop nicely.</p>
  
  <p>There are obvious alternatives (using a vector, for example!) but it seems to me that there should be some reasonably neat way of doing this which I'm just not seeing at the moment.</p>
  
  <p>Thanks in advance for any help :)</p>