Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#8315 closed Bugs (fixed)

tee function template does not work for std streams

Reported by: Claudio Bley Owned by: Jonathan Turkanis
Milestone: To Be Determined Component: iostreams
Version: Boost 1.53.0 Severity: Problem
Keywords: tee iostreams Cc:

Description

General Info

OS:: Windows 7 64bit

Compiler:: MSVC 10

The Code

std::ostringstream out;
boost::iostreams::tee(out);

Compiler Output / Error

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
 ]

Analysis

The parameter is given to the tee function template as a const-reference:

template<typename Sink>
tee_filter<Sink> tee(const Sink& snk) 
{ return tee_filter<Sink>(snk); }

Quoting the documentation:

The function parameter is a non-const reference if Sink is a stream or stream buffer type, and a const reference otherwise.

Actually, this really does not apply to the function parameter, but rather to the tee_filter ctor parameter.

So, this boils down to passing a const-reference type to a non-const-reference type as an argument.

Proposed Solution

Remove the "const" qualifier from the tee function parameter(s).

Change History (3)

comment:1 by Steven Watanabe, 10 years ago

Removing the const will break tee for non-standard streams. tee needs to be overloaded. (Actually, it should use perfect forwarding).

comment:2 by Steven Watanabe, 10 years ago

Resolution: fixed
Status: newclosed

(In [83505]) Make tee work correctly for std::streams. Fixes #8315.

comment:3 by Daniel James, 9 years ago

(In [84303]) Merge iostreams to release. Fixes #8315, #8385, #8460.

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.

Note: See TracTickets for help on using tickets.