Better slicing

Oskar Linde oskar.lindeREM at OVEgmail.com
Thu Mar 9 00:36:15 PST 2006


Lionello Lunesu wrote:
 > "NN" <NN_member at pathlink.com> wrote in message
 > news:dun61g$30be$1 at digitaldaemon.com...
 >> What about more powerful slicing, like e.g. in Python ?
 >>
 >> char[] x;
 >>
 >> char[] y = x[0 : x.size : 1];
 >> char[] y = x[x.size : 1]; // Same
 >>
 >> char[] z = x[x.size : 0 : -1]; // Reverse
 >> char[] z = x[x.size :: -1]; // Same
 >>
 >> // Maybe with D syntax
 >> char[] x;
 >>
 >> char[] y = x[0 .. x.size .. 1];
 >> char[] y = x[x.size .. 1]; // Same
 >>
 >> char[] z = x[x.size .. 0 .. -1]; // Reverse
 >> char[] z = x[x.size .. .. -1]; // Same

This has similarities to Norbert Nemec's suggestion from 2 years ago:

http://homepages.uni-regensburg.de/~nen10015/documents/D-multidimarray.html

> To reverse an array is a costly operation, and it would not be a good idea 
> to hide it behind a fancy operator, it will hide the penalty.

Reversing arrays doesn't have to be expensive if you have strided array 
references. (By this, I'm not suggesting that D should make simple 1-D 
dynamic arrays strided.)

(Sorry for reversing the top-posting.)

/Oskar






More information about the Digitalmars-d mailing list