C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Signed sizes

From: Tiago Freire <tmiguelf_at_[hidden]>
Date: Tue, 10 Dec 2024 06:32:15 +0000
I agree with making things uniform, but I completely disagree with making "signed" the default interface for indexing.

While indexing very high values is dubiously wrong, indexing negative values is unquestionably wrong.
There's no such thing as negatively indexing into an array, that is always wrong (even if achieves the exact same effect as a too high number), there's also no such thing as a container with a negative amount of slots.
Plus, if you make indexing signed you would need to perform double side bounds checking of indexes, while with unsigned you just need to do a one side bounds check since unsigned values can not be smaller than 0.
Signed integers are weird.
Unsigned integers should be the default, not the exception.

Received on 2024-12-10 06:32:19