Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-05-28 14:24:40

Sebastian Redl <sebastian.redl_at_[hidden]> writes:

> David Abrahams wrote:
>>Sebastian Redl <sebastian.redl_at_[hidden]> writes:
>>>The main (only, really, when it comes down to it) difference
>>>between a signed and an unsigned integer is that an unsigned integer is
>>>defined never to have a value less than 0. There are very valid reasons
>>>to enforce such a restriction,
>>For example?
> Various physical quantities only make sense for non-negative
> values.

Likewise, some make sense only between 0 and 2*pi or between 0 and 1,

that doesn't mean we should define a separate floating point type to
represent each of these ranges.

> It
> would be conceivable to use a boundless unsigned integer as the value
> type in the PQS library. Things like length - something cannot have
> negative length, and having that restriction enforced by the type itself
> would be convenient.

Maybe those kinds of enforcements should be handled generally, with a
range-checked wrapper.

> I have no doubt that there are other applications too. size_t is
> unsigned - of course, a boundless int should not be necessary for
> specifying array indices, but similar applications might exist.

The unsigned builtins exist in order to squeeze the most out of a
limited number of bits. An arbitrary precision int doesn't have that

Dave Abrahams
Boost Consulting

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