Opened 5 years ago

Closed 5 years ago

Last modified 5 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:


General Info

OS:: Windows 7 64bit

Compiler:: MSVC 10

The Code

std::ostringstream 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>'
 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


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).

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by Steven Watanabe

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

comment:2 Changed 5 years ago by Steven Watanabe

Resolution: fixed
Status: newclosed

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

comment:3 Changed 5 years ago by Daniel James

(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.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Jonathan Turkanis.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.