Boost C++ Libraries: Ticket #8327: iostream header and std::cout in hpp files must be removed. https://svn.boost.org/trac10/ticket/8327 <p> I think that direct including iostream header and ostream instance like cout, cerr or so must be deprecated. </p> <p> Reasons </p> <ul><li>to support environment which ostream is forbidden like embedded systems. </li><li>to entrust output type to library user. </li></ul><p> Alternative plan is to replace ostream instance to template-type as below.<br /> </p> <ul><li>before <div class="wiki-code"><div class="code"><pre><span class="n">template</span> <span class="o">&lt;</span><span class="kr">typename</span> <span class="n">Iter</span><span class="o">&gt;</span> <span class="kt">void</span> <span class="n">PrintTest</span><span class="p">(</span><span class="n">Iter</span> <span class="n">first</span><span class="p">,</span> <span class="n">Iter</span> <span class="n">last</span><span class="p">)</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">distance</span><span class="p">(</span><span class="n">first</span><span class="p">,</span> <span class="n">last</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;: ( &quot;</span><span class="p">;</span> <span class="k">for</span> <span class="p">(</span><span class="n">Iter</span> <span class="n">iter</span> <span class="o">=</span> <span class="n">first</span><span class="p">;</span> <span class="n">iter</span> <span class="o">!=</span> <span class="n">last</span><span class="p">;</span> <span class="o">++</span><span class="n">iter</span><span class="p">)</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="o">*</span><span class="n">iter</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; &quot;</span><span class="p">;</span> <span class="p">}</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;)&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="p">}</span> </pre></div></div></li><li>after <div class="wiki-code"><div class="code"><pre><span class="n">template</span> <span class="o">&lt;</span><span class="kr">typename</span> <span class="n">Stream</span><span class="p">,</span> <span class="kr">typename</span> <span class="n">Iter</span><span class="o">&gt;</span> <span class="kt">void</span> <span class="n">PrintTest</span><span class="p">(</span><span class="n">Stream</span><span class="o">&amp;</span> <span class="n">ostr</span><span class="p">,</span> <span class="n">Iter</span> <span class="n">first</span><span class="p">,</span> <span class="n">Iter</span> <span class="n">last</span><span class="p">)</span> <span class="p">{</span> <span class="n">ostr</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">distance</span><span class="p">(</span><span class="n">first</span><span class="p">,</span> <span class="n">last</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;: ( &quot;</span><span class="p">;</span> <span class="k">for</span> <span class="p">(</span><span class="n">Iter</span> <span class="n">iter</span> <span class="o">=</span> <span class="n">first</span><span class="p">;</span> <span class="n">iter</span> <span class="o">!=</span> <span class="n">last</span><span class="p">;</span> <span class="o">++</span><span class="n">iter</span><span class="p">)</span> <span class="p">{</span> <span class="n">ostr</span> <span class="o">&lt;&lt;</span> <span class="o">*</span><span class="n">iter</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; &quot;</span><span class="p">;</span> <span class="p">}</span> <span class="n">ostr</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;)&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="p">}</span> </pre></div></div></li><li>Even if ostream header is not included, std::distance() and std::endl are ignored until PrintTest() is substantialized. </li></ul><p> Subject </p> <ul><li>boost/algorithm/searching/detail/debugging.hpp </li><li>boost/graph/graph_utility.hpp </li><li>boost/math/constants/generate.hpp </li><li>boost/pending/relaxed_heap.hpp </li><li>or so ... </li></ul> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8327 Trac 1.4.3 John Maddock Sat, 23 Mar 2013 11:29:39 GMT <link>https://svn.boost.org/trac10/ticket/8327#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8327#comment:1</guid> <description> <p> There are several points here: </p> <p> 1) The compiler is entitled to reject <a class="missing wiki">PrintTest</a> if std::endl and std::distance have not been declared <em>even if the function is never instantiated</em>. GCC and Clang are examples that will do this. </p> <p> 2) iostream and associated headers are part of the standard, it's not unreasonable to reply on them. </p> <p> 3) The only Math lib header mentioned above is only ever used when generating new numeric constants so should never be an issue in practice. </p> <p> There is an include of &lt;iostream&gt; in boost/math/tools/precision.hpp which isn't needed which I'll remove. </p> <p> And finally, please file one bug report per library. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>pjtsu</dc:creator> <pubDate>Sat, 23 Mar 2013 13:43:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8327#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8327#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/8327#comment:1" title="Comment 1">johnmaddock</a>: </p> <p> Thank you for your reply. </p> <blockquote class="citation"> <p> 1) The compiler is entitled to reject <a class="missing wiki">PrintTest</a> if std::endl and std::distance have not been declared <em>even if the function is never instantiated</em>. GCC and Clang are examples that will do this. </p> </blockquote> <p> Sorry, I did not check on GCC.<br /><br /> </p> <blockquote class="citation"> <p> 2) iostream and associated headers are part of the standard, it's not unreasonable to reply on them. </p> </blockquote> <p> Windows GUI application can build with cout, but the application don't have I/O console.<br /> Therefore <strong>ostringstream</strong>, <strong>ofstream</strong> or user-customized stream like may be used alternativelly.<br /> If stream argument is not ostream but template-type, independent class from ostream can be used. (as like <strong>CDumpContext</strong> in MFC. ... though std::endl must be removed.)<br /> </p> <div class="wiki-code"><div class="code"><pre><span class="c1">// not so great</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">Iter</span><span class="o">&gt;</span> <span class="kt">void</span> <span class="n">PrintTest</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">ostream</span><span class="o">&amp;</span> <span class="n">ostr</span><span class="p">,</span> <span class="n">Iter</span> <span class="n">first</span><span class="p">,</span> <span class="n">Iter</span> <span class="n">last</span><span class="p">);</span> <span class="c1">// good</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">Stream</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Iter</span><span class="o">&gt;</span> <span class="kt">void</span> <span class="n">PrintTest</span><span class="p">(</span><span class="n">Stream</span><span class="o">&amp;</span> <span class="n">ostr</span><span class="p">,</span> <span class="n">Iter</span> <span class="n">first</span><span class="p">,</span> <span class="n">Iter</span> <span class="n">last</span><span class="p">);</span> </pre></div></div><p> <br /> </p> <blockquote class="citation"> <p> 3) The only Math lib header mentioned above is only ever used when generating new numeric constants so should never be an issue in practice. </p> <p> There is an include of &lt;iostream&gt; in boost/math/tools/precision.hpp which isn't needed which I'll remove. </p> <p> And finally, please file one bug report per library. </p> </blockquote> <p> All right. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>pjtsu</dc:creator> <pubDate>Sat, 23 Mar 2013 15:04:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8327#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8327#comment:3</guid> <description> <p> Incidentally, override of std::endl and std::flush for <strong>CDumpContext</strong> in MFC is as below. (I checked only vs2010.) </p> <div class="wiki-code"><div class="code"><pre><span class="kr">inline</span> <span class="n">CDumpContext</span><span class="o">&amp;</span> <span class="k">operator</span> <span class="o">&lt;&lt;</span> <span class="p">(</span><span class="n">CDumpContext</span><span class="o">&amp;</span> <span class="n">me</span><span class="p">,</span> <span class="n">CDumpContext</span> <span class="o">&amp;</span> <span class="p">(</span><span class="o">*</span><span class="n">_f</span><span class="p">)(</span><span class="n">CDumpContext</span><span class="o">&amp;</span><span class="p">))</span> <span class="p">{</span> <span class="k">return</span> <span class="p">(</span><span class="o">*</span><span class="n">_f</span><span class="p">)(</span><span class="n">me</span><span class="p">);</span> <span class="p">}</span> <span class="k">namespace</span> <span class="n">std</span> <span class="p">{</span> <span class="kr">inline</span> <span class="n">CDumpContext</span><span class="o">&amp;</span> <span class="n">flush</span><span class="p">(</span><span class="n">CDumpContext</span><span class="o">&amp;</span> <span class="n">me</span><span class="p">)</span> <span class="p">{</span> <span class="n">me</span><span class="p">.</span><span class="n">Flush</span><span class="p">();</span> <span class="k">return</span> <span class="n">me</span><span class="p">;</span> <span class="p">}</span> <span class="kr">inline</span> <span class="n">CDumpContext</span><span class="o">&amp;</span> <span class="n">endl</span><span class="p">(</span><span class="n">CDumpContext</span><span class="o">&amp;</span> <span class="n">me</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">me</span> <span class="o">&lt;&lt;</span> <span class="n">_T</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">flush</span><span class="p">;</span> <span class="p">}</span> <span class="p">};</span> </pre></div></div> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sat, 23 Mar 2013 16:53:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8327#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8327#comment:4</guid> <description> <p> class Stream and CDumpContext are entirely specific to MSVC, they won't appear anywhere in Boost code. </p> <p> Also note that std::iostream code is only used in Boost.Math for debugging/diagnostic purposes (when BOOST_MATH_INSTRUMENT is defined). What <em>is</em> used is boost::lexical_cast which depends on std::stringstream and related code. Removing that is much harder - verging on impossible if we want to retain multiprecision support - which we certainly do. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sat, 23 Mar 2013 17:05:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8327#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8327#comment:5</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/83532" title="Reorganise header inclusion to minimise dependencies on &lt;iostream&gt; and ...">[83532]</a>) Reorganise header inclusion to minimise dependencies on &lt;iostream&gt; and &lt;boost/lexical_cast.hpp&gt;. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8327" title="#8327: Support Requests: iostream header and std::cout in hpp files must be removed. (closed: fixed)">#8327</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sun, 24 Mar 2013 12:02:01 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8327#comment:6 https://svn.boost.org/trac10/ticket/8327#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/83537" title="Make use of lexical_cast (and hence multiprecision support) dependent ...">[83537]</a>) Make use of lexical_cast (and hence multiprecision support) dependent on there being an iostreams lib. Should allow use on embedded platforms, especially WinCE. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8327" title="#8327: Support Requests: iostream header and std::cout in hpp files must be removed. (closed: fixed)">#8327</a>. </p> Ticket