SGI's locale facets (time_put,time_get,...) ???
brent verner
brent@rcfile.org
Thu Aug 10 18:43:00 GMT 2000
in case the last email I sent was unclear... here is a patch (which
causes no failures to the testsuite, as well as causing the attached
testcase to pass) implementing what I think to be a sane solution to
the Arithmetic extractor / std::ws problem.
let me know if you'd like me to submit a patch for the testsuite
to include the attached test case, I assume it should go into
27_io/istream_extractor_arith.cc.
Cheers,
Brent
NOTES:
the following explains the logic a bit more... an excerpt from my
post to comp.lang.c++. It appears that DR60 _may_ have language
that does not require the sentry for
istream& operator>>(istream& (*pf)(istream&))
to skip whitespace, which could allow sentry to set both eofbit
and failbit per DR195, effectively fixing the problem which the
attached patch to libstdc++-v3 addresses/solves.
1: basic_istream<charT,traits>& operator>>
(basic_istream<charT,traits>& (* pf)(basic_istream<charT,traits>&))
is required to create a sentry with noskipws==false, according to
Common requirements for formatted input.
2: the operator referenced above is used to apply the std::ws
manipulator to a stream.
3: After the manipulator std::ws extracts (6:) _any_ whitespace from
its stream failbit cannot be set for the istream.
4: DR195 proposes that sentry ctor setstate(eofbit|failbit) when
consuming whitespace and eof() is read.
5: setstate(eofbit|failbit) within sentry's ctor makes Facts 1,2,3
impossbile to implement in the case where whitespace
immediately precedes eof() on the istream, as shown below.
int anum;
std::istringstream iss(" 10 ");
iss >> anum;
iss >> std::ws;
setting (failbit|eofbit) inside the sentry ctor will cause
the stream state to be:
iss.fail() == true;
iss.eof() == true;
after std::ws is applied to the istream.
If we decide that only failbit can be set within
sentry::sentry to continue to have std::ws _appear_ to
behave as defined, we run into another problem:
std::istringstream isn(" 1 2 3 4 5 6 ");
while( isn >> num ){
std::cout << num << std::endl;
}
after the "6" has been extracted/converted, there remains
whitespace until eof(). the next instance of sentry::sentry
will cause this whitespace to be consumed, read eof() and
setstate(eofbit), causing an infinite loop since there is
no way for failbit to be set to cause the while() to break.
My questions are these. Should the Arithmetic Operators described
in 27.6.1.2.2 loop infinitely as in the last given example? Should
std::ws be able to leave the stream with failbit set even when
whitespace was extracted?
If the answer is 'no' to both questions, a simple, and logical
solution appears to be specifying (or explicitly allowing) that
the Arithmetic Extractors 'setstate(failbit)' if its sentry's
boolean conversion does not evaluate to true.
Side note: std::ws can never successfully extract any whitespace from
an istream since its sentry's construction does so before the
std::ws function is called, correct?
--
Damon Brent Verner o _ _ _
Cracker Jack? Surprise Certified _o /\_ _ \\o (_)\__/o (_)
brent@rcfile.org _< \_ _>(_) (_)/<_ \_| \ _|/' \/
brent@linux1.org (_)>(_) (_) (_) (_) (_)' _\o_
More information about the Libstdc++
mailing list