Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-08-24 09:46:44

----- Original Message -----
From: <helmut.zeisel_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, August 24, 2001 4:38 AM
Subject: [boost] Re: Unlimited integer: conversion to built-in int?

> --- In boost_at_y..., Jens Maurer <Jens.Maurer_at_g...> wrote:
> > helmut.zeisel_at_a... wrote:
> > > A user of my big_int implementation asked me if
> > > I could add implicit conversion to less precise integral types.
> >
> > No.
> >
> I agree.
> In the meanwhile I realized that he actually needs
> a conversion to bool,
> which is false for zero and true for non-zero,
> i.e., he wants to write code like
> unlimited n;
> ...
> while(n) {...}
> This sounds reasonable to me.

Not to me.
An integer number doesn't have, IMHO, a generally defined mapping to
When we didn't have a bool type, we used to rely on the fact that the
boolean expression (n) evaluated as (n!=0), therefore we get used to write
(n) ,(!n) instead of (n!=0),(n==0).
I think that such a shortcut is appropriate only for objects with a well
defined true/false mapping, such as pointers, but not for true numbers
(numeric values having mathematical meaning).

For example, chances are that the above predicate should have been (n>0)
instead of (n!=0).
Alternatively, writing explicitly (n!=0) can help to make sure that the loop
body must reach that condition properly (such as decrement/increment one by
one only)

Fernando Cacciola
Sierra s.r.l.

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