Subject: [boost] [iostreams] Add char_traits to the Device concept
From: thomas weidner (thomas001le_at_[hidden])
Date: 2010-03-14 12:20:39
i came across this issue when trying to use iostreams with a custom
character class and custom character traits. The main problem is, that
iostreams assumes std::streampos as the position type for all devices.
Some parts of iostreams, like detail::indirect_streambuf honor the char
traits' custom pos_type, but this will cause build failures as the
underlying device (even code_converter) uses std::streampos as position
My proposal is to add an associated character traits type to a Device. A
Device type whould therefore not only provide information about the
underlying character type, but also about the used pos_type, off_type
and code conversion (not) done.
I would even use traits different from
std::char_traits<Ch>/iostreams::char_traits<Ch> as default character
traits for most devices. Most devices like for example
file_descriptor_sink don't do any code conversion, so a pos_type which
contains a mbstate_t is useless and leaves the user with the impression,
that code conversion *is* done. A simple integral type like C's off_t
should do fine. Let's call those traits binary_char_traits for now.
As an implication of this a
iostreams::stream_buffer<file_descriptor_sink> should use the Device's
char traits type, so should be a std::basic_streambuf<char,
binary_char_traits<char> >. Especially it whould not be useable with
std::iostream. This is IMO a nice and very clean result, as an iostream
expects characters on which code conversion has been performed. You
whould need to plug a code_converter in between.
Some thoughts about iostreams::code_converter. Perhaps we should change
the Codecvt template parameter to a second traits type. This traits type
will become the code_converter's associated char traits type. the
codecvt type could be an extra template parameter or is simply
codecvt, code_converter_traits_state_type>. this whould be the same
mechanism as code conversion in the stdlib works (using std::codecvt
Comments to my thoughts are very welcome.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk