Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-01-12 12:35:37


christopher diggins wrote:
> ----- Original Message -----
> From: "Jonathan Turkanis" <technews_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Tuesday, January 11, 2005 10:56 PM
> Subject: [boost] Re: Re: Re: Re: Re: Functions as Filters (was Program
> Reuse...)
>
>
>> Hi Christopher,
>>
>> I think I haven't made my main point clear, so let me try to
>> rephrase it.
>
> Hi Jonathan,
>
> I am pretty sure I understand you. Before I continue, I first want to
> know one thing, do you (or anyone else) see any value of being able
> to write C++ code like the following?
>
> #include <iostream>
> #include <fstream>
> #include "fxn_filters.hpp"
>
> using namespace std;
>
> void ToUpper() {
> char c;
> while (cin.get(c)) cout.put(c);
> }

I don't see why this is better than

   struct toupper_filter : input_filter {
        template<typename Source>
        int get(Source& src) { return toupper(boost::io::get(src)); }
   };

and its cousins.

> int main() {
> fstream("input.txt") > Filter(ToUpper);
> }

This won't work, since fstream("input.txt") produces a temporary object which
cannot be used to initialize a non-const reference. Therefore operator< would
have to be declared to take a const reference, and the non-const extraction
functions would not be usable.

I have to go no, but I'll continue this discussion later.

>
> Christopher Diggins
> http://www.cdiggins.com
>

Jonathan


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