title: How to get unique pairs of values from a stl set
body: <p>I have a stl set of integers and I would like to iterate through all unique pairs of integer values, where by uniqueness I consider val1,val2 and val2,val1 to be the same and I should only see that combination <em>once</em>.</p>
  
  <p>I have written this in python where I use the index of a list (clusters):</p>
  
  <pre><code>for i in range(len(clusters) - 1):
      for j in range(i+1,len(clusters)):
         #Do something with clusters[i],clusters[j])
  </code></pre>
  
  <p>but without an index I am not sure how I can achieve the same thing with a stl set and iterators.  I tried  out:</p>
  
  <pre><code>for (set&lt;int&gt;::iterator itr = myset.begin(); itr != myset.end()-1; ++itr) {
      cout &lt;&lt; *itr;
  }
  </code></pre>
  
  <p>but this fails as an iterator doesn't have a - operator.</p>
  
  <p>How can I achieve this, or must I use a different container?</p>