This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Gabriel Dos Reis wrote:
> | > What do you do with a const stream?

"Vladimir Merzliakov" <wanderer@rsu.ru> writes:
> | 
> | class Parser {
> |    std:ifstream m_in;
> |    public: bool isOK() const { return m_in.is_open(); }
> | };
> | 
> | ?

Gabriel Dos Reis wrote:
> You're telling me that you need a const member function because you
> need a constant member function.  A parser, is kind of stream.  My
> question was what do you with a const stream.  If your const parser is
> not OK what do you to it?

Any decent design process by a designer unaware of the defect in the
standard (and that's what it is) would probably specify that the
Parser::isOK method is const, because it does not alter either the actual
or the logical state of any of the members.  Good C++ design requires that
const be used as much as possible, because it greatly simplifies the
maintainance of the code (when undesired write operations occur, there are
fewer places to look.

I have regularly written parser and lexer classes in C++ that have const
methods.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]