title: Dropping "const int" qualifiers in template operator[]
body: <p>I have looked at several post about const qualifiers, but I am not able to figure out how to fix this issue. I am building a class that is modeled after the STL map class, and I am using the STL set class as the base class:</p>
  
  <pre><code>template &lt;class Key, class Value&gt;
  class map : public std::set &lt;std::pair&lt;Key, Value&gt; &gt; {
  public:
      typedef std::set&lt;std::pair&lt;Key, Value&gt; &gt; parent;
      typedef typename std::set&lt;std::pair&lt;Key, Value&gt; &gt;::iterator iterator;
  
      // constructors
      map() : parent() {}
      map(map&lt;Key, Value&gt;&amp; m) : parent(m) {}
  
      // definition for subscript operator
      Value&amp; operator [] (const Key &amp;);
  
      // overloaded methods from set
      void erase(Key&amp;);
      void erase(iterator&amp; itr) {
          parent::erase(itr);
      }
  
      int count(Key&amp;);
      iterator find(Key&amp;);
      iterator lower_bound(Key&amp; k) {
          return parent::lower_bound(k);
      }
  
      iterator upper_bound(Key&amp; k) {
          return parent::upper_bound(k);
      }
  
      // not found iterator
      iterator end() {
          return parent::end();
      }
  
  };
  </code></pre>
  
  <p>The problem is with the operator[] overload function, which looks like:</p>
  
  <pre><code>template &lt;class Key, class Value&gt;
  Value&amp;  map&lt;Key, Value&gt;::operator[] (const Key&amp; k) {
      std::pair&lt;Key, Value&gt; test;
      test.first = k;
  
      std::pair&lt;iterator, bool&gt; where = parent::insert(test);
  
      return (*(where.first)).second;
  }
  </code></pre>
  
  <p>The compiler is giving me the error "...map.h:108:16: Binding of reference to type 'int' to a value of type 'const int' drops qualifiers". I realize that it's seeing that (*(where.first)).second is evaluated to a "const int" and I am returning it to an "int" because I have declared a map as:</p>
  
  <pre><code>map&lt;std::string, int&gt; mymap;
  mymap["one"] = 1;
  </code></pre>
  
  <p>It appears that the <code>std::pair&lt;...&gt;</code> is being defined as <code>std::pair&lt;std::string, const int&gt;</code> instead of <code>std::pair&lt;std::string, int&gt;</code>. At least this is my conjecture. I must be missing something simple, but I am not seeing it. Any help is greatly appreciated.</p>