title: c++ : comparison function for next_permutation
body: <p>I want to use <code>std::next_permutation()</code> on a vector of Object. </p>
  
  <p>To do so I have to define a comparison function that defines the <code>&lt; operator</code> between two Objects (otherwise it will take a default comparison operator that has an unpredictable behavior)</p>
  
  <p>But sometimes I got two Objects that are equal (according to my criteria) and so <code>Object1 &lt; Object2</code> and <code>Object2 &lt; Object1</code> both return <code>false</code> so next_permutation() turns indefinitely...</p>
  
  <p><strong>EDIT</strong> : here is a simple example of what I have (the loop never ends)</p>
  
  <p><strong>MyObject.h :</strong> </p>
  
  <pre><code>class MyObject {
      int param;
      MyObject(int i);
  
  };
  </code></pre>
  
  <p><strong>Main.cpp :</strong></p>
  
  <pre><code>bool comparison (MyObject * o1, MyObject * o2) { return (o1-&gt;param &lt; o2-&gt;param); }
  
  int main(){
  
      std::vector&lt;MyObject*&gt; myVector;
      myVector.push_back(new MyObject(0));
      myVector.push_back(new MyObject(1));
      myVector.push_back(new MyObject(1));
  
      std::sort(myVector.begin(), myVector.end(), comparison);
  
      do{
          printf("%i, %i, %i \n", myVector[0]-&gt;param, myVector[1]-&gt;param, myVector[2]-&gt;param);
      } while(std::next_permutation(myVector.begin(), myVector.end()), comparison);
  
      return 0;
  }
  </code></pre>
  
  <p>So how could I handle that case ? How does the default <code>&lt; operator</code> handles this case ?</p>