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?


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


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