title: Overload C++ set insert
body: <p>Is it possible to overload the compare operator in a string set so that it defines two elements with edit distance &lt;= 1 as identical?</p>
  
  <p>This is my failed attempt:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;set&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int min(int x, int y, int z) 
  {
     return min(min(x, y), z);
  }
  
  int getEditDist(string&amp; str1, string&amp; str2, int m, int n)
  {
      if (str1[m-1] == str2[n-1])
          return getEditDist(str1, str2, m-1, n-1);
      return 1 + min ( getEditDist(str1,  str2, m, n-1),
                       getEditDist(str1,  str2, m-1, n),
                       getEditDist(str1,  str2, m-1, n-1)
          );
  }
  
  
  class editDist
  {
  public:
      bool operator () (string&amp; str1, string&amp; str2)
          {
              return(getEditDist(str1, str2, str1.length(), str2.length()) &lt;= 1);
          }
  };
  
  
  int main(int argc, char* argv[])
  {
  
      string id1 = "AAA";
      string id2 = "BBB";
      string id3 = "BAB";
      set&lt;string,editDist&gt; my_set;
      //set&lt;string&gt; my_set;
      set&lt;string,editDist&gt;::const_iterator itr;
      //set&lt;string&gt;::const_iterator itr;
      my_set.insert(id1);
      my_set.insert(id2);
      my_set.insert(id3);
      for(itr = my_set.begin();itr != my_set.end();++itr) cout&lt;&lt;*itr&lt;&lt;endl;
      return(0);
  }
  </code></pre>
  
  <p>I'm not even sure it's coded correctly since it doesn't compile.</p>