std.array suggestion

Oskar Linde olREM at OVEnada.kth.se
Thu Mar 9 13:54:14 PST 2006


David Medlock wrote:

> Oskar Linde wrote:
> <snip>

> I would also add:

I think the following are redundant as functions as they all have an
equivalent splice syntax:

> T[]  left( T[] array, int n )
identical to array[0..n];

> T[]  right( T[] array, int n )
identical to array[$-n..$];

> T[]  skip( T[] array, int n )
identical to array[n..$];

> In my own personal parsing stuff I regularly use the above plus:
> 
> T[]  countUntil( char[] str, bool delegate(char) pred );
> T[]  countWhile( char[] str, bool delegate(char) pred );

I assume those should return a size_t and not a T[]?
If I understand correctly, those functions would be similar to find, but
return arr.length instead of -1 when no matching element is found? (The
second one would also invert the predicate.)

> So skipping whitespace becomes:
> 
> text = skip( text.countWhile( delegate bool(char c){ c<=32; } ) );

/Oskar



More information about the Digitalmars-d mailing list