title: C++ double iterator loop for collision detection
body: <p>First things first, I'm very new to C++! So I've got a standard list of objects representing elements in 2d space, and I want to do some basic collision detection. My first idea (coming from a mostly Java background...) is to compare each object with each other object, calling an function to check for intersection on each pair or objects. This would have been simple in Java, taking the first item of the ArrayList, comparing it with the second, third, etc. then taking the second item, comparing it with the third, fourth, etc. This is the approach I took with the problem in C++, but I'm using an iterator (rather than direct element access like I'd do in Java), but iterators are meant to be used linearly, right? So direct access isn't suitable.</p>
  
  <p>So my question is how do I perform this algorithm? I'm also reasonably sure this isn't the best way to do (very basic) collision detection, so any advice on that would be welcomed too. Here's my (non-working) code.</p>
  
  <pre><code>for (list&lt;Box&gt;::iterator p = mBoxes.begin(); p != mBoxes.end(); p++) {
      for (list&lt;Box&gt;::iterator q = mBoxes.begin() + p); q != mBoxes.end(); q++) {
          if (p-&gt;isIntersecting(q)) {
              p-&gt;changeDirection();
              q-&gt;changeDirection();
          }
      }
  }
  </code></pre>
  
  <p>This should illustrate the method I'm attempting, but of course my try of <code>mBoxes.begin() + p</code> doesn't work!</p>