title: Reversing the content of a set in C++
body: <p>I want to reverse the contents of a <code>std::set</code>(Not just iterating theough it in reverse, but reversing the contents iteslf). I found that <code>std::set</code> takes the compare as a function object for its constructor. Hence I came up with the following code to do the same:</p>
  
  <pre><code>#include &lt;set&gt;
  using namespace std;
  struct Comparator
  {
      Comparator(bool g) : m_g(g){}
       bool operator()(int i1, int i2) const
      {
          if(m_g)
          {
              return i1&gt;i2;
          }
          return i1&lt;i2;
      }
          bool m_g;
  };
  
  int main(int argc, char** argv)
  {
      Comparator l(false);
      set&lt;int,Comparator&gt; a(l);
      a.insert(1);
      a.insert(2);
      a.insert(3);
      Comparator g(true);
      set&lt;int,Comparator&gt; b(g);
      copy(a.begin(), a.end(), inserter(b, b.begin()));
      a = b;
      return 0;
  }
  </code></pre>
  
  <p>This seems to work in VC9. But is this code correct? My doubt arises due to the fact my <code>Comparator</code> has state associated with it. Are comparators are allowed to have states?</p>