Topic: sentry::sentry(), arithmetic extractors, and std::ws


Author: brent verner <brent@rcfile.org>
Date: 2000/08/11
Raw View
On 10 Aug 2000 at 19:27 (+0000), Dietmar Kuehl wrote:
| Hi,
| In article <20000810112511.A8519@rcfile.org>,
|   brent verner <brent@rcfile.org> wrote:
| [lengthy analysis snipped]
|
| A few notes:
| - I think there is a DR on the "inserters" and "extractors" for the
|   manipulators not being considered formatted output/input functions.
|   It simply does not make sense having 'std::cin >> std::dec' skip
|   leading whitespace.

I have read DR60, which I assume you are referring to. If the
requirement for a sentry with noskipws==false is dropped for the
'istream& operator>>(istream& (*pf)(istream))', then the sentry
can be specified to setstate(eofbit|failbit) to accomodate the
expected behavior of std::ws and and Arithmetic Extractors.

| - I think there is another DR mandating that the input and output
|   functions are supposed to set 'failbit' if the 'sentry' did not
|   convert to true.

I have not seen a DR relating to this, but would be unnecessary, I
believe, if DR60 + DR195, allow sentry to setstate(failbit|eofbit)
w/o breaking other parts of the standard's behavior.

| I think each of these changes would resolve your problem. If this is
| not the case, please say so and I would go through the analysis again,
| making detailed comments.

I'll look over the possibility of _not_ sentry not skipping whitespace
for the operator>>() mentioned above.

Thanks for your response,
  Brent

--
Damon Brent Verner                        o      _     _         _
Cracker Jack? Surprise Certified  _o     /\_   _ \\o  (_)\__/o  (_)
brent@rcfile.org                _< \_   _>(_) (_)/<_    \_| \   _|/' \/
brent@linux1.org               (_)>(_) (_)        (_)   (_)    (_)'  _\o_

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: brent verner <brent@rcfile.org>
Date: 2000/08/10
Raw View
(originally attempted to send to newsgroup comp.std.c++)

Hi,

  I've been considering the following in trying to find a solution to
a problem related to Arithmetic Extractor behavior. If any of this is
incorrect, please enlighten me. My confusion follows. I hope you can
help me understand the solution.


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?


Thanks.
  Brent

--
Damon Brent Verner
brent@rcfile.org
brent@linux1.org

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: brent verner <brent@rcfile.org>
Date: 2000/08/10
Raw View
Hi,

Please allow me to correct myself...

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

The first line of the above paragraph should read:

  >         If we decide that only eofbit can be set within

Thank you,
  Brent Verner

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Dietmar Kuehl <dietmar_kuehl@yahoo.com>
Date: 2000/08/11
Raw View
Hi,
In article <20000810112511.A8519@rcfile.org>,
  brent verner <brent@rcfile.org> wrote:
[lengthy analysis snipped]

A few notes:
- I think there is a DR on the "inserters" and "extractors" for the
  manipulators not being considered formatted output/input functions.
  It simply does not make sense having 'std::cin >> std::dec' skip
  leading whitespace.

- I think there is another DR mandating that the input and output
  functions are supposed to set 'failbit' if the 'sentry' did not
  convert to true.

I think each of these changes would resolve your problem. If this is
not the case, please say so and I would go through the analysis again,
making detailed comments.
--
<mailto:dietmar_kuehl@yahoo.com>
<http://www.dietmar-kuehl.de/>


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]