Modify

Ticket #8315 (closed Bugs: fixed)

Opened 13 months ago

Last modified 11 months ago

tee function template does not work for std streams

Reported by: Claudio Bley Owned by: 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).

Attachments

Change History

comment:1 Changed 13 months 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 13 months ago by steven_watanabe

  • Status changed from new to closed
  • Resolution set to fixed

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

comment:3 Changed 11 months ago by danieljames

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.