My main gripe with going with int is that it eliminates the possibility of making ilength() a noop that just returns .length on 32. The assert would still be necessary.<br><br><div class="gmail_quote">On Thu, Feb 17, 2011 at 9:48 AM, 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><div></div><div class="h5">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 pedantic<br>
> nature of 64-bit to 32-bit integer conversions in cases where using size_t<br>
> doesn't cut it. Examples are storing arrays of indices into other arrays,<br>
> where using size_t would be a colossal waste of space if it's safe to assume<br>
> none of the arrays will be billions of elements long.<br>
><br>
> int ilength(T)(T[] arr) {<br>
> assert(arr.length <= int.max);<br>
> return cast(int) arr.length;<br>
> }<br>
><br>
> Usage:<br>
><br>
> int[] indices;<br>
> auto array = returnsArray();<br>
> indices ~= array.ilength;<br>
><br>
> This cuts down on the excessive verbosity of an explicit cast that's safe<br>
> 99.999 % of the time and encourages sprinkling it into code even if for the<br>
> foreseeable future it will be compiled in 32-bit mode.<br>
><br>
> Two questions:<br>
><br>
> 1. Is everyone ok with me adding this as a convenience function to<br>
> std.array?<br>
> 2. int or uint? I used int only b/c that was the example on the newsgroup,<br>
> but I think uint makes more sense.<br>
<br>
</div></div>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>
<div><div></div><div class="h5">_______________________________________________<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>