Allowing access to container objects in C++
<p>I have a class like the one below:</p>

<pre><code>class Foo {
private:
    std::map&lt;std::string, Bar*&gt; bars_by_name;
    std::map&lt;std::string, Baz*&gt; bazs_by_name;
};
</code></pre>

<p>Now I'd like to allow the user to access both collections but hide the implementation detail that I'm storing the objects into std::maps. Instead, I'd like to have member functions that return e.g. const iterators for the collections and possibly even a custom iterator that returns objects from both collections, since Bar and Baz belong to the same class hierarchy. Considering style, what would be the proper way to do this in C++? In Java, I'd probably set the method's return type to Iterable or wrap the collection into an unmodifiableCollection.</p>
