Fair points.  You've convinced me (since I didn't have a very strong opinion before).  Let's go with int.  I've also come to believe that ilength is the best name because it's negligible extra typing compared to .length, so people will actually use it.  Proposed function for inclusion in object:<br>
<br><span style="font-family: courier new,monospace;">/**</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Returns the length of an array as a 32-bit signed integer.  Verifies <br>
with an assert that arr.length <= int.max unless this can be proven<br>at compile time.  This is a useful shortcut for getting the<br>length of a arrays that cannot plausibly have length longer than<br>int.max (about 2 billion) as a 32-bit integer even if building<br>
for a 64-bit target.  It's also useful for converting an array length<br>to a signed integer while verifying the safety of this<br>conversion if asserts are enabled.<br>*/<br style="font-family: courier new,monospace;">
</span><span style="font-family: courier new,monospace;">@property int ilength(T)(const T[] arr) pure nothrow @safe {<br>    static if(size_t.sizeof > uint.sizeof || T.sizeof == 1) {<br>        assert(arr.length <= int.max,<br>
            "Cannot get integer length of array with >int.max elements."<br>        );<br>    }<br>    <br>    return cast(int) arr.length;<br>}<br><br><br></span><span style="font-family: courier new,monospace;"></span><div class="gmail_quote">
On Thu, Feb 17, 2011 at 2:24 PM, Don Clugston <span dir="ltr"><<a href="mailto:dclugston@googlemail.com">dclugston@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On 17 February 2011 17:10, David Simcha <<a href="mailto:dsimcha@gmail.com">dsimcha@gmail.com</a>> wrote:<br>
> Can you elaborate on why?  Unsigned seems like the perfect type for an array<br>
> length.<br>
<br>
</div>An array length is a positive integer, you want to treat it as an<br>
integer, not as a bag of bits.<br>
Using an unsigned types is like using a cast, to be avoided whenever<br>
possible. They're a breeding ground for bugs,<br>
and a disturbingly large fraction of programmers don't understand them.<br>
<div class="im"><br>
<br>
<br>
On 17 February 2011 18:02, David Simcha <<a href="mailto:dsimcha@gmail.com">dsimcha@gmail.com</a>> wrote:<br>
> My main gripe with going with int is that it eliminates the possibility of<br>
> making ilength() a noop that just returns .length on 32.  The assert would<br>
> still be necessary.<br>
<br>
</div>But the assert adds value.<br>
Note that an assert is only required on arrays of size 1 --  ubyte, byte, char.<br>
On everything else, it's still a no-op.<br>
<div class="im"><br>
<br>
> On Thu, Feb 17, 2011 at 9:48 AM, Don Clugston <<a href="mailto:dclugston@googlemail.com">dclugston@googlemail.com</a>><br>
> wrote:<br>
>><br>
>> On 17 February 2011 14:59, David Simcha <<a href="mailto:dsimcha@gmail.com">dsimcha@gmail.com</a>> wrote:<br>
>> > Hey guys,<br>
>> ><br>
>> > Kagamin just came up with a simple but great idea to mitigate the<br>
>> > pedantic<br>
>> > nature of 64-bit to 32-bit integer conversions in cases where using<br>
>> > size_t<br>
>> > doesn't cut it.  Examples are storing arrays of indices into other<br>
>> > arrays,<br>
>> > where using size_t would be a colossal waste of space if it's safe to<br>
>> > assume<br>
>> > none of the arrays will be billions of elements long.<br>
<br>
<br>
</div><div><div></div><div class="h5">>> >  int or uint?  I used int only b/c that was the example on the<br>
>> > newsgroup,<br>
>> > but I think uint makes more sense.<br>
>><br>
>> I *strongly* oppose uint. We should take every possible opportunity to<br>
>> reduce usage of unsigned numbers.<br>
>> 'i' implies immutable.<br>
>> How about intlength  (or intLength ?)<br>
_______________________________________________<br>
phobos mailing list<br>
<a href="mailto:phobos@puremagic.com">phobos@puremagic.com</a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/phobos" target="_blank">http://lists.puremagic.com/mailman/listinfo/phobos</a><br>
</div></div></blockquote></div><br>