Boost logo

Boost Users :

From: aj_dicks (alex_dicks_at_[hidden])
Date: 2002-04-10 17:35:42


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?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net