Boost C++ Libraries: Ticket #8315: tee function template does not work for std streams
https://svn.boost.org/trac10/ticket/8315
<h1 class="section" id="GeneralInfo">General Info</h1>
<p>
OS:: Windows 7 64bit
</p>
<p>
Compiler:: MSVC 10
</p>
<h1 class="section" id="TheCode">The Code</h1>
<div class="wiki-code"><div class="code"><pre><span class="n">std</span><span class="o">::</span><span class="n">ostringstream</span> <span class="n">out</span><span class="p">;</span>
<span class="n">boost</span><span class="o">::</span><span class="n">iostreams</span><span class="o">::</span><span class="n">tee</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
</pre></div></div><h1 class="section" id="CompilerOutputError">Compiler Output / Error</h1>
<pre class="wiki">Boost\Boost_1_53\boost/iostreams/tee.hpp(208): error C2440: '<function-style-cast>' : cannot convert from 'const std::ostringstream' to 'boost::iostreams::tee_filter<Device>'
with
[
Device=std::ostringstream
]
No constructor could take the source type, or constructor overload resolution was ambiguous
recurse.cpp(14) : see reference to function template instantiation 'boost::iostreams::tee_filter<Device> boost::iostreams::tee<std::ostringstream>(const Sink &)' being compiled
with
[
Device=std::ostringstream,
Sink=std::ostringstream
]
</pre><h1 class="section" id="Analysis">Analysis</h1>
<p>
The parameter is given to the tee function template as a const-reference:
</p>
<div class="wiki-code"><div class="code"><pre><span class="k">template</span><span class="o"><</span><span class="k">typename</span> <span class="n">Sink</span><span class="o">></span>
<span class="n">tee_filter</span><span class="o"><</span><span class="n">Sink</span><span class="o">></span> <span class="n">tee</span><span class="p">(</span><span class="k">const</span> <span class="n">Sink</span><span class="o">&</span> <span class="n">snk</span><span class="p">)</span>
<span class="p">{</span> <span class="k">return</span> <span class="n">tee_filter</span><span class="o"><</span><span class="n">Sink</span><span class="o">></span><span class="p">(</span><span class="n">snk</span><span class="p">);</span> <span class="p">}</span>
</pre></div></div><p>
Quoting the documentation:
</p>
<blockquote>
<p>
The function parameter is a non-const reference if Sink is a stream
or stream buffer type, and a const reference otherwise.
</p>
</blockquote>
<p>
Actually, this really does not apply to the function parameter, but rather to the tee_filter ctor parameter.
</p>
<p>
So, this boils down to passing a const-reference type to a non-const-reference type as an argument.
</p>
<h1 class="section" id="ProposedSolution">Proposed Solution</h1>
<p>
Remove the "const" qualifier from the tee function parameter(s).
</p>
en-usBoost C++ Libraries/htdocs/site/boost.png
https://svn.boost.org/trac10/ticket/8315
Trac 1.4.3Steven WatanabeWed, 20 Mar 2013 15:01:53 GMT
<link>https://svn.boost.org/trac10/ticket/8315#comment:1 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8315#comment:1</guid>
<description>
<p>
Removing the const will break tee for non-standard streams. tee needs to be overloaded. (Actually, it should use perfect forwarding).
</p>
</description>
<category>Ticket</category>
</item>
<item>
<dc:creator>Steven Watanabe</dc:creator>
<pubDate>Wed, 20 Mar 2013 15:45:45 GMT</pubDate>
<title>status changed; resolution set
https://svn.boost.org/trac10/ticket/8315#comment:2
https://svn.boost.org/trac10/ticket/8315#comment:2
<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/83505" title="Make tee work correctly for std::streams. Fixes #8315.">[83505]</a>) Make tee work correctly for std::streams. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8315" title="#8315: Bugs: tee function template does not work for std streams (closed: fixed)">#8315</a>.
</p>
TicketDaniel JamesThu, 16 May 2013 22:10:19 GMT
<link>https://svn.boost.org/trac10/ticket/8315#comment:3 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8315#comment:3</guid>
<description>
<p>
(In <a class="changeset" href="https://svn.boost.org/trac10/changeset/84303" title="Merge iostreams to release. Fixes #8315, #8385, #8460.
Not merging ...">[84303]</a>) Merge iostreams to release. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8315" title="#8315: Bugs: tee function template does not work for std streams (closed: fixed)">#8315</a>, <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8385" title="#8385: Bugs: Incorrect link on documentation webpage. (closed: fixed)">#8385</a>, <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8460" title="#8460: Bugs: Doc errors (closed: fixed)">#8460</a>.
</p>
<p>
Not merging the fallthrough macro, as config support hasn't been merged yet.
And not merging the build changes, as I don't know if they're ready.
</p>
</description>
<category>Ticket</category>
</item>
</channel>
</rss>