Re: D slicing

2013-06-18 Thread Colin Grogan
On Monday, 17 June 2013 at 23:48:36 UTC, Ali Çehreli wrote: On 06/17/2013 04:34 PM, Colin Grogan wrote: Wondering what way I'd go about this, I want to slice an array into two arrays. First array containing every even index (i.e. 0,2,4,6,8..$) Second slice containing every odd index (i.e.

D slicing

2013-06-17 Thread Colin Grogan
Hi all. Wondering what way I'd go about this, I want to slice an array into two arrays. First array containing every even index (i.e. 0,2,4,6,8..$) Second slice containing every odd index (i.e. 1,3,5,7,9..$) -- be some issue with using $ depending on if orig length is odd or even. Can work

Re: D slicing

2013-06-17 Thread bearophile
Colin Grogan: Reading the articles on array slicing its not clear if its possible. I presume Walter thinks that slicing with a stride is a not common enough operation to put it into D. His choices on such things are a bit arbitrary. One way to do it: import std.stdio, std.array,

Re: D slicing

2013-06-17 Thread Andrej Mitrovic
On Monday, 17 June 2013 at 23:34:46 UTC, Colin Grogan wrote: auto orig = [1,2,3,4,5,6,7]; auto sliceEven = orig[0..$..2]; auto sliceOdd = orig[1..$..2]; But I dont think thats possible? Not with arrays, they must be contiguous. But you can use ranges instead: - import std.stdio;

Re: D slicing

2013-06-17 Thread Ali Çehreli
On 06/17/2013 04:34 PM, Colin Grogan wrote: Wondering what way I'd go about this, I want to slice an array into two arrays. First array containing every even index (i.e. 0,2,4,6,8..$) Second slice containing every odd index (i.e. 1,3,5,7,9..$) -- be some issue with using $ depending on if