Boost logo

Boost :

From: christopher diggins (cdiggins_at_[hidden])
Date: 2005-01-10 19:32:38


----- Original Message -----
From: "Jonathan Turkanis" <technews_at_[hidden]>
>> I compiled and successfuly ran this on Visual C++ 7.1. What are the
>> chances something like this could find its way into the iostreams
>> library?
>
> If you can convince me that it's useful.

It is not that useful, unless you are inexperienced in C++, or just want
something that is simple, easy to use and "good enough" (I fall into all of
these camps). I understand that these may not be sufficient motivations to
make an addition to the library, especially one written in the style of the
STL, which is so rigorous.

> If it really were possible to reuse existing code, as you orginally
> suggested,
> then it would be a clear win. However, I haven't yet seen an example of a
> pre-existing procedure which meets the requirements of the proc_as_filter
> class.

You mean a simple void procedure with no parameters, which reads from
standard in, and outputs to standard out? The main() from many programs fits
this bill.

> Therefore, I first must decide whether writing a filter as a function
> which
> reads from standard input and writes to standard output is ever the best
> way to
> write a filter, given the other choices that the library provides.

It is possibly never the "best way", technically speaking.

> You clearly
> think the answer is yes, but I'd like to see some examples.
>
> Second, is there any reason to prefer functions with the signature
[a, b, c]
> ?

The only reason to ever choose a over b or c, is simplicity and ease of use.

>> This is what I am ultimately striving for. Is there any reason why the
>> source() and sink() can not be assumed to be cin and cout
>> respectively when absent?
>
> Yes. When you use the pipe operator you don't always want to form a
> complete
> chain:
>
> filtering_ostream out(filter1() | filter2() | filter3());
> out.push(sink());
>
> In a real world example the first and second lines might be at different
> locations in a program.

But in the example of:

  source() | filter1() | filter2() | sink();

Then why couldn't we just write:

  filter1() | filter2();

And assume that source and sink were cin and cout respectively.

Christopher Diggins
Object Oriented Template Library (OOTL)
http://www.ootl.org


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk