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

Gabriel Dos Reis gdr@integrable-solutions.net
Fri Aug 13 16:44:00 GMT 2004


Joe Buck <Joe.Buck@synopsys.COM> writes:

| 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.

Const-correctness is a good design principle.  However, it is not a dogma,
which is why I'm aksing the question.

-- Gaby



More information about the Libstdc++ mailing list