Boost logo

Boost :

From: Steven Siloti (ssiloti_at_[hidden])
Date: 2007-06-19 23:27:25

As long as we're talking about a new I/O library for C++ I'll go ahead
and give my $0.02.

I think some consideration should be given to designing an I/O library
on the basis of STL concepts. After all, files aren't really streams,
they're arrays of bytes (or a similar basic element). Thus it seems more
natural to model a class representing a file after std::vector rather
than some stream concept. In fact I've done exactly this using memory
mapped file I/O as part of another project where I needed to store many
Bidirectional Iterators to various files and it worked quite well.

Streaming I/O could be done with iterators. Conceptually streams can be
thought of as simply being specialized iterators with different syntax.
For example, a socket class would present a pair of iterators, one Input
Iterator and one Output Iterator (or maybe just a single Forward
Iterator?). They would be theoretically never-ending but the Input
Iterator would end up equal to some end iterator when the socket has
been closed and there is no further data available.

Filtering could be done with wrapper iterators that consume elements
from a stored iterator and emit elements of a potentially different type
after performing some transformation. Wrapper iterators would be
considered equal if the iterators they are holding are equal.

Several of the current standard algorithms could be made usefully in
such a scheme. And obviously a great many could be created for I/O
centric operations.

This seems to me like a more natural and flexible interface than IO
Streams while making transfers to and from STL containers more convenient.

Steven Siloti

Boost list run by bdawes at, gregod at, cpdaniel at, john at