#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 , 10 years ago
comment:2 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Removing the const will break tee for non-standard streams. tee needs to be overloaded. (Actually, it should use perfect forwarding).