Streamed input for rational, badbit vs failbit
Is there an error in the declaration of template <typename IntType> std::istream& operator>> (std::istream& is, rational<IntType>& r) in boost.hpp? The lines if (c != '/') is.clear(std::istream::badbit); appear in the function definition, as the format is num/den, so we expect a slash character. However, is setting the stream to bad correct? Shouldn't it be failbit instead? The standard states that badbit indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error from a file); failbit indicates that an input operation failed to read the expected characters, or that an output operation failed to generate the desired characters. Also, to cite precedence from the standard, it stipulates that the std::complex type's extraction operator should call is.setstate(ios::failbit) if bad input is found. What is confusing, however, is that Stroustrup's example input operation for complex sets badbit (section 21.3.5 in the third edition of his bible). So who is right out of: me, rational.hpp, the C++ standard, Stroustrup? Is it more than two of these, and if so, where is my misunderstanding?
participants (1)
-
aj_dicks