title: Expose Member Data Through Read-only Iterator
body: <p>I have a class 'MyClass' which contains some data stored in <code>std::map</code>s. The standard maps contain pointers to objects, e.g.</p>
  
  <pre><code>private:
     std::map&lt;int,Object*&gt; m_data;
  </code></pre>
  
  <p>I want to expose the data to the outside world but I do not want other classes/functions to be able to modify either (i) the map <code>m_data</code> or (ii) the objects pointed to by the values in <code>m_data</code>. I would like some hypothetical function, say <code>getDataBegin()</code> which returns an iterator over the data which has the properties above. For example I want the following <em>pseudo-code</em> examples to fail:</p>
  
  <pre><code>iterator_type itr = myclass.getDataBegin();
  erase(itr); // not allowed because we cannot modify m_data;
  itr.second = NULL; // not allowed to change content of m_data (falls under first rule)
  itr.second-&gt;methodWithSideEffect(); // not allowed because changes content of object pointed to.
  </code></pre>
  
  <p>In short you could say I am after read-only access to some member data. Is this at all possible in a nice way, and if so then how could I go about it? </p>