[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] [PATCH] Fix trailing whitespace detection in stream_cast()
From: |
Vadim Zeitlin |
Subject: |
Re: [lmi] [PATCH] Fix trailing whitespace detection in stream_cast() |
Date: |
Wed, 29 Jan 2020 15:54:39 +0100 |
On Wed, 29 Jan 2020 12:53:50 +0000 Greg Chicares <address@hidden> wrote:
GC> On 2020-01-29 12:06, Vadim Zeitlin wrote:
GC> > On Tue, 28 Jan 2020 18:46:15 +0000 Greg Chicares <address@hidden> wrote:
GC> [...]
GC> > GC> std::istringstream interpreter("123");
GC> > GC> int n = -1;
GC> > GC> interpreter >> n;
GC> > GC> what is this code
GC> > GC> !(interpreter >> std::ws).eof())
GC> > GC> supposed to do?
GC> > GC> - it invokes the std::ws extractor; in this case, eofbit was set
GC> > GC> by the ctor, so the effect is to set failbit; then
GC> > GC> - eof() is called; it ignores failbit, inspects eofbit, and
GC> > GC> returns true. Right?
GC> >
GC> > Yes, except for "set by the ctor" part which I don't understand.
[...]
GC> and the sentry's ctor (not the std::istream's ctor) sets eofbit.
This answers my question, thanks.
GC> | But the
GC> | important thing is that the state of the stream after extracting ws() is
GC> | completely ignored here and the exclamation sign tests the state of the
GC> | stream after calling eof() on it.
GC>
GC> I believe the exclamation sign in this context:
GC>
GC> > GC> what is this code
GC> > GC> !(interpreter >> std::ws).eof())
GC> > GC> supposed to do?
GC>
GC> actually tests the return value of eof():
Oops, yes, sorry for inadvertently adding more confusion and thanks for
clearing it up.
VZ
pgp8knZ8DvPRF.pgp
Description: PGP signature