Should basic_*stream::is_open() be const?
Jonathan Wakely
cow@compsoc.man.ac.uk
Fri Aug 13 12:51:00 GMT 2004
On Fri, Aug 13, 2004 at 01:10:17PM +0200, Andreas Kohn wrote:
> On Fri, 2004-08-13 at 12:44, Gabriel Dos Reis wrote:
> >
> > Still, I find the need to this addition very dubious.
> >
> Without this methods being const (which they should be IMHO from a
> logical perspective, as they do not change the internal state of the
> stream but simply return state information), methods that use these
> methods can not be const.
> This "can not be const" will easily cascade into upper layers, which
> reduces quality and safeness of the code.
I agree with you from a theoretical perspective (and need no convincing
of the merits of const-correctness) but I'm surprised it makes much
practical difference whether you can test if a const std::fstream is open
or not. If you find your const std::fstream is not open() what do you
plan to do? You can't open it or perform I/O, because it's const.
I am sure I've missed something, but I'm tempted to consider a const
fstream a case of applying the rule a little too rigidly.
(I have no opinion on whether the patch should be applied, so please
don't take this as an objection)
jon
--
"'Tis an ill wind that blows no minds."
- Mal2
More information about the Libstdc++
mailing list