Topic: std::bitset extractor
Author: Gennaro Prota <gennaro_prota@yahoo.com>
Date: Sat, 14 Sep 2002 17:11:54 CST Raw View
>From the description of std::bitset's extractor (23.3.5.3):
----
template <class charT, class traits, size_t N>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
4 A formatted input function (27.6.1.2).
5 Effects: Extracts up to N (single-byte) characters from is.
Stores these characters in a temporary object str of type string,
then evaluates the expression x = bitset<N>(str). Characters are
extracted and stored until any of the following occurs:
N characters have been extracted and stored;
end-of-file occurs on the input sequence;
the next input character is neither 0 or 1 (in
which case the input character is not extracted).
6 If no characters are stored in str, calls
is.setstate(ios::failbit) (which may throw ios_base::failure
(27.4.4.3).
7 Returns: is.
----
Simple question: what is the behavior when no characters are extracted
(2nd and 3rd condition)?
a) the expression x = bitset<N>(str), with str being an empty
string, is evaluated. Thus the bitset is at the end "empty".
b) the bitset object is not touched
c) behavior is undefined
Genny.
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Allan_W@my-dejanews.com (Allan W)
Date: Mon, 16 Sep 2002 19:19:46 +0000 (UTC) Raw View
Gennaro Prota <gennaro_prota@yahoo.com> wrote
> >From the description of std::bitset's extractor (23.3.5.3):
>
> ----
> template <class charT, class traits, size_t N>
> basic_istream<charT, traits>&
> operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
>
> 4 A formatted input function (27.6.1.2).
> 5 Effects: Extracts up to N (single-byte) characters from is.
> Stores these characters in a temporary object str of type string,
> then evaluates the expression x = bitset<N>(str). Characters are
> extracted and stored until any of the following occurs:
>
> — N characters have been extracted and stored;
> — end-of-file occurs on the input sequence;
> — the next input character is neither 0 or 1 (in
> which case the input character is not extracted).
>
> 6 If no characters are stored in str, calls
> is.setstate(ios::failbit) (which may throw ios_base::failure
> (27.4.4.3).
> 7 Returns: is.
>
> ----
>
> Simple question: what is the behavior when no characters are extracted
> (2nd and 3rd condition)?
>
> a) the expression x = bitset<N>(str), with str being an empty
> string, is evaluated. Thus the bitset is at the end "empty".
>
> b) the bitset object is not touched
>
> c) behavior is undefined
Reading the above statements, it seems obvious to me that your
choice (a) is the correct one. The standard doesn't seem to make
any exceptions for an empty string; the assignment still takes
place.
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]