Boost C++ Libraries: Ticket #4617: Use of stringstreams in numeric/ublas/io https://svn.boost.org/trac10/ticket/4617 <p> Not 100% sure it is a bug, but use of additional string streams seems a bit odd. </p> <pre class="wiki"> template&lt;class E, class T, class ME&gt; // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. std::basic_ostream&lt;E, T&gt; &amp;operator &lt;&lt; (std::basic_ostream&lt;E, T&gt; &amp;os, const matrix_expression&lt;ME&gt; &amp;m) { typedef typename ME::size_type size_type; size_type size1 = m ().size1 (); size_type size2 = m ().size2 (); std::basic_ostringstream&lt;E, T, std::allocator&lt;E&gt; &gt; s; s.flags (os.flags ()); s.imbue (os.getloc ()); s.precision (os.precision ()); s &lt;&lt; '[' &lt;&lt; size1 &lt;&lt; ',' &lt;&lt; size2 &lt;&lt; "]("; if (size1 &gt; 0) { s &lt;&lt; '(' ; if (size2 &gt; 0) s &lt;&lt; m () (0, 0); for (size_type j = 1; j &lt; size2; ++ j) s &lt;&lt; ',' &lt;&lt; m () (0, j); s &lt;&lt; ')'; } for (size_type i = 1; i &lt; size1; ++ i) { s &lt;&lt; ",(" ; if (size2 &gt; 0) s &lt;&lt; m () (i, 0); for (size_type j = 1; j &lt; size2; ++ j) s &lt;&lt; ',' &lt;&lt; m () (i, j); s &lt;&lt; ')'; } s &lt;&lt; ')'; return os &lt;&lt; s.str ().c_str (); } </pre><p> why do we create stringstream 's' and serialize everything in memory and only then pump it to 'os'? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4617 Trac 1.4.3 Steven Watanabe Wed, 01 Sep 2010 14:33:46 GMT <link>https://svn.boost.org/trac10/ticket/4617#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4617#comment:1</guid> <description> <p> Using a stringstream is a common way of making sure that width is handled correctly. </p> </description> <category>Ticket</category> </item> <item> <author>Kostya <seraphym@…></author> <pubDate>Wed, 01 Sep 2010 16:41:38 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4617#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4617#comment:2</guid> <description> <p> could you, please, elaborate a bit? or maybe post a link to some discussion on the matter? </p> </description> <category>Ticket</category> </item> </channel> </rss>