title: Container class that encapsulates map with custom iterators
body: <p>I'd like to make a class that encapsulates a <code>std::map</code> and acts like a container of a different type, like this:</p>
  <pre><code>class Item
  {
  public:
      Item(int number, const char *text) :
          Number(number),
          Text(text)
      {}
  
      int Number;
      std::string Text;
  };
  
  class Container
  {
  public:
  
      void add(Item item)
      {
          Map.insert(std::make_pair(item.Number, item.Text));
      }
  
      Container::iterator begin();
      Container::iterator end();
  
  private:
      std::map &lt;int, string&gt; Map;
  };
  </code></pre>
  <p>I want to use it like this, without using the map's <code>first</code> and <code>second</code>:</p>
  <pre><code>int main()
  {
      Container container;
      container.add(Item(0, &quot;foo&quot;));
      container.add(Item(1, &quot;bar&quot;));
  
      for (auto &amp;elem : container)
      {
          // elem is an Item
          cout &lt;&lt; elem.Number &lt;&lt; elem.Text &lt;&lt; endl;
      }
  }
  </code></pre>
  <p>I tried implementing a custom iterator that encapsulated a map iterator, but I got stuck on the <code>-&gt;</code> operator, which must return the address of an <code>Item</code> object (right?) There's no <code>Item</code> object whose address I can return.</p>
  <p>How do you do this?</p>