[comp.lang.c++] ostream_with_assign versus specialization of cout?

benson@odi.com (Benson I. Margulies) (12/20/89)

I've got a derived class of ostream that internally sets the unitbuf
flag. I tried

   cout = one_of_my_streams;

The operator= goes and reinitializes the stream, clearing the 
crucial flag (unitbuf). If operator= is going to do this,
it seems that cout should have been a pointer. As it is,
one can't make cout be another type, it seems.

-- 
Benson I. Margulies

jss@jra.ardent.com (12/22/89)

In article <1989Dec19.175438.12843@odi.com> benson@odi.com () writes:
>I've got a derived class of ostream that internally sets the unitbuf
>flag. I tried
>
>   cout = one_of_my_streams;
>
>The operator= goes and reinitializes the stream, clearing the 
>crucial flag (unitbuf). If operator= is going to do this,
>it seems that cout should have been a pointer. As it is,
>one can't make cout be another type, it seems.

I tend to agree.  The predefined classes ought to have been
pointers rather than streams, however I didn't feel that
iostreams could make that radical a departure from streams.
I originally tried having pointers and #defining the predefined

	#define cout (*cout_ptr) 

but it eventually became clear to me that macros here were
a bad idea. (If nothing else they create confusing error messages
for beginners.)

My own coding style uses a global ostream* and assigns
&cout to the global when appropriate rather than assigning 
streams to cout. 

For a long time I resisted having assignment of streams at all 
in iostream.  I finally allowed it primarily for backward 
compatibility.  (Although it was a nightmare to implement)
But it was never clear to me what the semantics of the 
assignment should be.  

Jerry Schwarz
jss@ardent.com

benson@odi.com (Benson I. Margulies) (12/22/89)

In article <9806@ardent.UUCP> jss@jra.ardent.com () writes:
>In article <1989Dec19.175438.12843@odi.com> benson@odi.com () writes:
>>I've got a derived class of ostream that internally sets the unitbuf
>>flag. I tried
>>
>>   cout = one_of_my_streams;
>>
>>The operator= goes and reinitializes the stream, clearing the 
>>crucial flag (unitbuf). If operator= is going to do this,
>>it seems that cout should have been a pointer. As it is,
>>one can't make cout be another type, it seems.
>
>I tend to agree.  The predefined classes ought to have been
>pointers rather than streams, however I didn't feel that
>iostreams could make that radical a departure from streams.

Unfortunately, your coding style is not in the documentation,
so there is lots of code that is prone to just using cout.

As per my previous post today, making streambuf::init virtual
would make is possible to assign any stream that hides
all its specific functionality in the streambuf. 

At very least, there should be a kind of ostream which just forwards
the data off to some other stream.

-- 
Benson I. Margulies