Should basic_*stream::is_open() be const?

Andreas Kohn andreas@syndrom23.de
Fri Aug 13 15:41:00 GMT 2004


On Fri, 2004-08-13 at 16:34, Vladimir Merzliakov wrote:
> > | 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.
> > | 
> > | What are your doubts? Is there anything I might miss?
> > 
> > What do you do with a const stream?
> 
> class Parser {
>    std:ifstream m_in;
>    public: bool isOK() const { return m_in.is_open(); }
> };
> 
> ?

This is a very good example, thank you Vladimir.

--
Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: This is a digitally signed message part
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20040813/9db0c782/attachment.sig>


More information about the Libstdc++ mailing list