
Sebastian Redl <sebastian.redl@getdesigned.at> writes:
David Abrahams wrote:
Sebastian Redl <sebastian.redl@getdesigned.at> 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, or... 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 problem. -- Dave Abrahams Boost Consulting www.boost-consulting.com