[Iostreams] What about making code_converter from boost::iostreams flushable?

Hello, I would like to wrap an output stream buffer (std::streambuf) with boost::iostreams::code_converter to be able to use it both raw and with ont-the-fly encoding by the boost::iostreams::default_facet. namespace io = boost::iostreams; xxxstream stream; stream << "raw"; io::stream<io::code_converter<xxxodevice> > wrapper(*stream.rdbuf()); wrapper << L" and converted"; stream << " and another raw"; Running the code writes "raw and another raw and converted" instead of "raw and converted and another raw" to the stream. I found that first in destructor of io::code_converter is the conversion buffer flushed causing the output. I could create a new instance of io::code_converter for every output and always close it: namespace io = boost::iostreams; xxxstream stream; stream << "raw"; { io::stream<io::code_converter<xxxodevice> > wrapper(*stream.rdbuf()); wrapper << L" and converted"; } stream << " and another raw"; But I would feel better being able to reuse the io::code_converter. (Actually, I have it as a private field in a class now.) I would like to make the io::code_converter flushable to be able to combine the output more conveniently: namespace io = boost::iostreams; xxxstream stream; stream << "raw"; io::stream<io::code_converter<xxxodevice> > wrapper(*stream.rdbuf()); wrapper << L" and converted" << std::flush; stream << " and another raw"; I added the support to io::code_converter rather that inheriting from it. What do you think about it? Would you accept it to boost or is it better to make flushable my inherited class? I am attaching a patch to code_converter.hpp from boost 1.35.0. I could provide a test for it too. Thank you, Ferda
participants (1)
-
Ferdinand Prantl