Signed Size

Use Int (i.e. signed) as the return type for *.size().

Mixing signed and unsigned integers is error-prone, and even pure unsigned arithmetic is often unintuitive and dangerous.

Classic C/C++ pitfall:

size_t i = 9;
while (i >= 0) {
    --i;
}

This is an endless loop, as i is always >= 0.
With unsigned 0 - 1 is not -1 but 0xffffffffffffffff, i.e. a really big, positive integer.

When working with sizes, subtraction is common. The moment you compute differences, you need a signed type anyway. So just use Int, then Size, SSize, and PtrDiff are unnecessary. UInt should be reserved for cases like hardware registers, bit masks, flags, and hashes — not used for sizes.

Anyone who needs more than 2GB of data in a single “byte array”, should please use a 64 bit platform. For bounds checking, the two comparisons x >= 0 and x < width may very well be reduced to a single UInt(x) < width by the compiler in an optimization step.

The C++ Experts About It

See also Going Native 2012, Day 2, Interactive Panel: Ask Us Anything