Boost logo

Boost :

From: Dean Sturtevant (deansturtevant_at_[hidden])
Date: 2001-01-11 23:51:19

I agree with the Stephen that the statement "while (m)" is
inappropriate. m is an integer type, not a boolean. There's no need
to provide operator!, which contrives to treat m like a boolean.
Instead, you want comparison with 0, or perhaps more principled, a
default-constructed item of the type. That is, the line should read

"while (m != 0)" or "while (m != IntType())", assuming the latter
construct is legal C++. And the comparison within the algorithm is a
little strange: Why would n % m be < 0 ? I would have thought that
any reasonable def of '%' would always yield non-negative numbers?

--- In boost_at_[hidden], "Stephen Silver" <boost_at_a...> wrote:

> The first problem is fairly minor. The gcd() function template in
> rational.hpp is documented as working for "any types for which the
> following operations are defined: =, +=, *=, /=, %, <". However, it
> contains the line
> while (m) {
> so it also requires that implicit conversion to bool be possible.
> is not a very desirable requirement, because user-defined conversion
> functions that convert to built-in types are not very safe (due to
> possibility of the conversion happening in contexts where it was not
> anticipated). Note that the above line could be changed to
> while (!!m) {
> which would have the advantage that it could work by means of
> instead of requiring implicit conversion to bool.

Boost list run by bdawes at, gregod at, cpdaniel at, john at