Use the size_t
type to hold collection sizes:
vector vectorX;
size_t intendedSize = 10;
// Some stuff here
if(vectorX.size() != intendedSize) {
...
}
Actually technically you should use vector::size_type
but in practice this is always a typedef for size_t
An int
is usually a signed 32-bit integer.
size_t
is usually an unsigned 64-bit integer (on 64-bit architectures) or an unsigned 32-bit integer (on 32-bit architectures).
(Note that the standard doesn't enforce those constraints. The ABI specifies this, for example the x86 and x86-64 ABI do.)