|
Boost : |
From: John Torjo (john_at_[hidden])
Date: 2003-04-24 01:29:09
Hi,
I've just looked at the more_io library
(http://groups.yahoo.com/group/boost/files/ -> more_io.zip)
I would have a comment:
The I/O streambuf wrapping seems unnecessary complex.
It can be easily emulated like this:
(the key function is basic_ios::init(&buf) )
(no unnecessary boost::io::...wrapping... classes)
// the following compiles and runs as expected
#include <iostream>
struct nul_streambuf : public std::streambuf
{
nul_streambuf() { this->setp( NULL, NULL); }
virtual int sync() { return 0; }
virtual int overflow(int nChar) { return 0; }
virtual std::streamsize xsputn(const char *S, std::streamsize N)
return N; }
};
template< class StreamBuf>
struct ostream_base : public std::ostream
{
typedef std::ostream base_class;
ostream_base()
: base_class( NULL)
{
this->init( &m_buf);
}
private:
StreamBuf m_buf;
};
class nul_ostream : public ostream_base< nul_streambuf>
{};
int main(int argc, char* argv[])
{
nul_ostream out;
out << "test" << std::endl;
}
Of course, the ostream_base can be templated (by char_type, traits_type).
Best,
John
-- John Torjo -- "Practical C++" column writer for builder.com.com Freelancer, C++ consultant mailto:john_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk