I was recently working with std::bitset<0>
and noticed something interesting with operator>>
:
The "specification" states that:
If no characters are extracted, is.setstate(ios_base::failbit) is called.
Does this still apply when "all possible N characters" (with N == 0) have been read? If so, does this imply that trying to read from an istream
into a bitset<0>
must always set failbit
?
The following unit test exhibits no consistent behavior across the compilers I had at hand:
BOOST_AUTO_TEST_CASE(io0) {
try {
std::stringstream ss{"1"};
ss.exceptions(std::ios::badbit | std::ios::failbit);
std::bitset<0> b;
ss >> b;
BOOST_TEST(false);
} catch(...) {
BOOST_TEST(true);
}
}
MSVC 2019 sets the failbit, whilst GCC 7.3.0 does not!