On Tue, 02 Apr 2013 16:32:21 -0400, Walter Bright <newshou...@digitalmars.com> wrote:

On 4/2/2013 12:47 PM, Andrei Alexandrescu wrote:
I used to lean a lot more toward this opinion until I got to work on a C++ codebase using signed integers as array sizes and indices. It's an pain all over the code - two tests instead of one or casts all over, more cases to worry
about... changing the code to use unsigned throughout ended up being an
improvement.

For example, with a signed array index, a bounds check is two comparisons rather than one.

Why?

struct myArr
{
   int length;
int opIndex(int idx) { if(cast(uint)idx >= cast(uint)length) throw new RangeError(); ...}
}

-Steve

Reply via email to