Topic: Error in specification of basic_istream::read ?


Author: Arch Robison <robison@kai.com>
Date: 1996/08/19
Raw View
I'm wondering if there is an error in the specification of
basic_istream<charT,traits>::read .  If not, could someone explain the
rationale for the apparent inconsistency between method read and method ignore?
According to the April 1995 and Jan 1996 drafts, when an end-of-file
occurs in the input sequence, the two functions behave differently:

 method ignore calls setstate(eofbit)

 method read calls setstate(failbit)

This seems inconsistent, since method ignore and read would seem to be
close cousins, with ignore discarding characters and read storing them.
Furthermore, another cousin, method readsome, calls setstate(eofbit) when
no more characters are available.

Perhaps I'm merely interpreting the draft incorrectly.
In [lib.istream], paragraph 3, it says:

    [lib.istream]

    3 If rdbuf()->sbumpc() or rdbuf()->sgetc() returns traits::eof(), then
      the input function, except as explicitly noted otherwise, completes
      its actions and does setstate(eofbit), which may throw
      ios_base::failure (_lib.iostate.flags_), before returning.

In [lib.istream.unformatted], the specification in question reads:

      basic_istream<charT,traits>& read(char_type* s, streamsize n);

      Effects:
 Extracts characters and stores them into successive locations of an
 array whose first element is designated by s.30) Characters are
 extracted and stored until either of the following occurs:

 --n characters are stored;

 --end-of-file occurs on the input sequence (in which case the function
 calls setstate(failbit), which may throw ios_base::failure
 (_lib.iostate.flags_)).
      Returns:
 *this.

Does the parenthetical note:

 "(in which case the function calls setstate(failbit)...)"

count as "except as explicitly noted otherwise"?  Or is setstate(eofbit)
*and* setstate(failbit) both supposed to be called?

Arch D. Robison       Kuck & Associates Inc.
robison@kai.com       1906 Fox Drive
217-356-2288        Champaign IL 61820
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]