Modify

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#8315 closed Bugs (fixed)

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 (0)

Change History (3)

comment:1 Changed 4 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 4 years ago by steven_watanabe

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

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

comment:3 Changed 4 years 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.

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain turkanis.
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.