title: Removing Duplicates from a list of sets
body: <p>I am implementing the famous "subsets of a set" problem.  I think I got a good working solution, but it contains duplicates.  I was hoping that list.unique() would take of the situation, but since for a set the == operator isn't defined, it doesn't work.  A set of sets doesn't fix the situation either (using list of sets now).</p>
  
  <p>Having 80% complete solution, I realize there is a better algorithm out there than one I came with.  But I am wondering if there is a clever way to remove the duplicates without completely rewriting the algorithm?</p>
  
  <p>Here's my code:</p>
  
  <p>MAIN.CPP:</p>
  
  <pre><code>#include "random.hpp"
  
  using namespace std;
  
  int main(void) {
  
      subsets2();
  
      getchar();
      return 0;
  }
  </code></pre>
  
  <p>Random.Cpp:</p>
  
  <pre><code>void getSubsets2(set&lt;int&gt; myset, list&lt;set&lt;int&gt; &gt; * ptr, int length) {
  
      if (length == 1) {
          ptr-&gt;push_back(myset);
      }
  
      else {
          set&lt;int&gt; second(myset);
          set&lt;int&gt;::iterator it;
          ptr-&gt;push_back(myset);
  
          it = myset.begin();
          myset.erase(it);
          it = second.begin();
          ++it;
          second.erase(it);
  
          getSubsets2(myset, ptr, length - 1);
          getSubsets2(second, ptr, length - 1);
      }
  }
  
  void subsets2(void) {
      const int N = 4;
      int myints[N] = {
          88, 33, 23, 22
      };
      set&lt;int&gt; myset(myints, myints + N);
      set&lt;int&gt; set2;
  
      list&lt;set&lt;int&gt; &gt; mylist;
  
      list&lt;set&lt;int&gt; &gt; * ptr;
      ptr = &amp; mylist;
  
      list&lt;set&lt;int&gt; &gt; ::iterator it;
      set&lt;int&gt;::iterator it2;
  
      getSubsets2(myset, ptr, N);
      mylist.unique();
  
  
      for (it = mylist.begin(); it != mylist.end(); ++it) {
          set2 = * it;
          for (it2 = set2.begin(); it2 != set2.end(); ++it2) {
              cout &lt;&lt; * it2 &lt;&lt; " ";
          }
          cout &lt;&lt; "\n";
      }
  
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>        22 23 33 88
          23 33 88
          33 88
          88
          33
          23 88
          88
          23
          22 33 88 
          33 88
          88
          33
          22 88
          88
          22
  </code></pre>