On Dec 23, 2004, at 3:02 PM, Christopher Smith wrote:


If I was doing:
filestream << "We have: " << std::scientific << 3.1415926 << std::endl;
At the end of the statement, I would expect that either an exception had been thrown (disk full, etc) or the filestream would have be left with the file stream using scientific notation.

You would also expect that either an exception had been thrown or the filestream had written out "We have: " and written and end of line and done a flush. Now, which is more surprising: that the logstream might not have done all of that if the log level wasn't enabled, or that it did none of what I said, but all of what you said? It is probably one of those matter of perspective things, but to me it seems far more logical that all operator<< stuff either be a nop or not, rather than just some of it.




If I'm writing to a basic_ostream, I have no guarantees that any effectual work is being done. I know that I'm formatting numbers into streams and sending them appending them to something, but I have no assurances that they are not being immediately discarded and have no generic mechanism to ever check that anything really happened.

There is nothing wrong with someone writing a streambuf (I think that is the right class, but forgive me if I'm wrong), that discarded everything, or looked at characters after a new line and discarded those that started with "DEBUG". That would not violate the contract for a streambuf. What my logstream does is end up with the same result, but without going through all the conversions the would precede streambuf level filtering.

However, if I was doing streambuf level filtering, even if I totally discarded everything, the manipulator would still change the state of the stream.



Reply via email to