 <p>I've had good luck with generic container functions:</p> <pre><code>template &lt;class Map&gt; void PrintMapToStream(std::ostream &amp;stream, const Map &amp;map) { for (auto &amp;elem : map) stream &lt;&lt; elem.second &lt;&lt; ' '; stream &lt;&lt; std::endl; } </code></pre> <p>Of course, this will fail with confusing error messages if you call it on something that doesn't allow you to iterate over pairs.</p>