title: an STL set of custom objects, each containing an STL set
body: <p>As is hopefully clear from the code below, I'd like to have a set of objects objectSet, each containing str1 and str2.  The set is keyed on str1, and any new objects with an str1 already in the objectSet will not be added, but if this new object has a different str2, I want to keep track of the fact that I saw it in the str2Set</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;set&gt;
  #include &lt;map&gt;
  
  using namespace std;
  
  class Object {
  public:
    string _str1;
    string _str2;
    set&lt;string&gt; _str2Set;
  
    bool operator&lt;(const Object&amp; b) const {
      return _str1 &lt; b._str1;
    }
  };
  
  int main(int argc, char *argv[]) {
    set&lt;Object&gt; objectSet;
  
    Object o;
    o._str1 = "str1";
    o._str2 = "str2";
  
    pair&lt; set&lt;Object&gt;::iterator, bool&gt; o_ret = objectSet.insert(o);
    if (o_ret.second == false) { // key exists
      int temp = (*o_ret.first)._str2Set.size(); // this is apparently fine
      (*o_ret.first)._str2Set.insert(o._str2); // this results in the error
    }
  
    return 0;
  }
  </code></pre>
  
  <p>Here is the compiler error:</p>
  
  <p>set_test.cpp: In function ‘int main(int, char**)’:
  set_test.cpp:31: error: passing ‘const std::set, std::allocator >, std::less, std::allocator > >, std::allocator, std::allocator > > >’ as ‘this’ argument of ‘std::pair, _Compare, typename _Alloc::rebind&lt;_Key>::other>::const_iterator, bool> std::set&lt;_Key, _Compare, _Alloc>::insert(const _Key&amp;) [with _Key = std::basic_string, std::allocator >, _Compare = std::less, std::allocator > >, _Alloc = std::allocator, std::allocator > >]’ discards qualifiers</p>
  
  <p>I understand this has to do with const but I still can't figure out exactly what the problem is or how to fix it.  Just getting rid of the const doesn't help.  </p>
  
  <p>As an alternative, I tried storing my Object's in </p>
  
  <pre><code>map&lt;string,Object&gt; objectSet;
  </code></pre>
  
  <p>And, strangely enough, the following works just fine:</p>
  
  <pre><code>  pair&lt; map&lt;string,Object&gt;::iterator, bool&gt; o_ret = objectSet.insert(pair&lt;string,Object&gt;(o._str1,o));
    if (o_ret.second == false) { // key exists
      o_ret.first-&gt;second._str2Set.insert(o._str2);
    }
  </code></pre>
  
  <p>Of course, that means I have to store str1 twice, which I consider wasteful. 
  Thanks for your input.  </p>