The C++11 standard (section 18.2) says:
(5). The type
ptrdiff_t
is an implementation-defined signed integer type that can hold the difference of two subscripts in an array object....(6). The type
size_t
is an implementation-defined unsigned integer type that is large enough to contain the size in bytes of any object.(7). [Note: It is recommended that implementations choose types for
ptrdiff_t
andsize_t
whose integer conversion ranks (4.13) are no greater than that ofsigned long int
unless a larger size is necessary to contain all the possible values. —end note]
From this we see that:
size_t
is specifically for byte-sizes of objects, and its companion ptrdiff_t
is specifically for math with array indices. uintmax_t
, on the other hand, is the largest unsigned integral type.
Depending on the platform uintmax_t
could be larger than size_t
.
We also know that:
sizeof
returns a size_t
, and the STL container size_type
s are typically identical to size_t
, so it makes sense to use size_t
in code that deals with sizeof
or STL containers.
Now mix in the fact the <cstdint>
is new-ish to C++, and I think it's pretty clear why established libraries like Boost have been using size_t
.