How would one go about using a stream with a parameter of charT corresponding to something other than char or wchar_t? I tried something like this:
std::basic_fstream<short, std::char_traits<short> > fs("test.txt", std::ios_base::out | std::ios_base::binary);
and it creates the file, writing to it does nothing, and flushing the stream sets the badbit.
I ask, because I have a template stream class that also accepts a parameter for the type of elements it contains, and I found that I didn't know how to implement things like seeking where the element type wasn't char or wchar_t. The problem is a simple one; if I try to seek 2^29 elements from the start in a stream with an element size of 4 bytes, I integer overflow on a 32bit two's complement system if I try to naively seek ahead the size of the element times the number of elements, using fseek() as a backend. Same for any operation that gets near the extremity of the offset type's precision, despite using those values being well-defined. Additionally, implementing peek() is complicated, since fungetc() is only guaranteed to store one character, so an element of a size greater than one isn't portable.
I tried using C++'s basic_streams, but most implementations don't seem to support streams of arbitrary width. If I were trying to support sane template parameters to my stream class, how should I go about implementing the back-end for file I/O? All other back-ends are easy.