On 21 Des, 22:01, Juha Nieminen <nos...@thanks.invalid> wrote:
> James Kanze wrote:
> >> For example, assume that vector1 has 3 000 000 000 elements
>
> > If you're on a 32-bit machine, vector1 can't have 3000000000
> > elements, so assuming it does is absurd.
>
> * Why not? You can certainly index 3 000 000 000 elements in a 32-bit
> system (at least if the size of the elements is 1 byte).
I'm not sure about that "can't", because it's easy to envision e.g. a
64-bit ptrdiff_t on a 32-bit machine.
But I think your argument is that if the address space size is 2^n,
and a vector has more than 2^(n-1) elements, then with n-bits signed
size type it gets rather messy, whereas unsigned type can handle it.
However, as noted earlier by Kai-Uwe Bux, that problem is already the
case for end()-begin(), so there already is an in-practice restriction
to 2^(n-1) elements if, with n-bits signed difference type, one wants
to avoid that mess.
In addition to the problem being already present, for practical
considerations, how often does one want > 2^(n-1) vector size?
And which OSes support it (Windows doesn't support it by default)?
Cheers,
- Alf
(Note: I've argued the opposite way at one time. Now I'm older and
less stupid.

)