Home » U++ Library support » U++ Library : Other (not classified elsewhere) » string[] causes many overload complaints
Re: string[] causes many overload complaints [message #20228 is a reply to message #20224] |
Mon, 02 March 2009 10:15   |
mr_ped
Messages: 826 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
Uhm, I was sort of joking in a cryptic way, so to make myself clear.
If you need a range from 0 to MaxN, and you have index I, with "signed" type you need to validate I by:
is_valid = ( 0 <= I && I <= MaxN );
With "unsigned" type for I the very same condition turns into:
is_valid = (I <= MaxN);
This is why I like to use 0..N ranges indexed by unsigned variables, the safety checks then cost me just single compare, not two of them.
Addendum:
And AFAIK there's no special use for negative index values in NTL containers, ranges are always from 0, so if I would design the NTL containers, the basic [] operator would work with unsigned type, not signed. Probably breaking the convention of many programmers writing "for (int i=0; i<max; i++)" ... I never care too much about conventions anyway, unless they make sense, and this one does not.
[Updated on: Mon, 02 March 2009 10:21] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Fri Jun 27 17:26:16 CEST 2025
Total time taken to generate the page: 0.03755 seconds
|