
Boost : 
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 20010824 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 builtin 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 nonzero,
>
> 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
true/false.
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.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk