[phobos] std.array.ilength

David Simcha dsimcha at gmail.com
Thu Feb 17 07:01:42 PST 2011


slength is good.  length32 is too hard to type.  I really want something
almost as terse as .length that can be used all over the place, anywhere
it's safe to assume that an array won't be billions of elements long.

On Thu, Feb 17, 2011 at 9:54 AM, Lars Tandle Kyllingstad <lars at kyllingen.net
> wrote:

> On Thu, 2011-02-17 at 15:48 +0100, Don Clugston wrote:
> > On 17 February 2011 14:59, David Simcha <dsimcha at gmail.com> wrote:
> > > Hey guys,
> > >
> > > Kagamin just came up with a simple but great idea to mitigate the
> pedantic
> > > nature of 64-bit to 32-bit integer conversions in cases where using
> size_t
> > > doesn't cut it.  Examples are storing arrays of indices into other
> arrays,
> > > where using size_t would be a colossal waste of space if it's safe to
> assume
> > > none of the arrays will be billions of elements long.
> > >
> > > int ilength(T)(T[] arr) {
> > >    assert(arr.length <= int.max);
> > >    return cast(int) arr.length;
> > > }
> > >
> > > Usage:
> > >
> > > int[] indices;
> > > auto array = returnsArray();
> > > indices ~= array.ilength;
> > >
> > > This cuts down on the excessive verbosity of an explicit cast that's
> safe
> > > 99.999 % of the time and encourages sprinkling it into code even if for
> the
> > > foreseeable future it will be compiled in 32-bit mode.
> > >
> > > Two questions:
> > >
> > > 1.  Is everyone ok with me adding this as a convenience function to
> > > std.array?
> > > 2.  int or uint?  I used int only b/c that was the example on the
> newsgroup,
> > > but I think uint makes more sense.
> >
> > I *strongly* oppose uint. We should take every possible opportunity to
> > reduce usage of unsigned numbers.
> > 'i' implies immutable.
> > How about intlength  (or intLength ?)
>
> Other suggestions:
>
> slength  (signed length / short length)
> length32
>
> -Lars
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20110217/d8da7376/attachment.html>


More information about the phobos mailing list