genetically modified slices - is it possible?

2013-11-15 Thread Alexandr Druzhinin
I'd like to get slice that's consist of begining one other slice and end of yet another slice (all slices belong to the same array of course). Is it possible? With iterators it's simple, but I can't manage do it with slices. http://dpaste.dzfl.pl/443cd4a1

Re: genetically modified slices - is it possible?

2013-11-15 Thread Adam D. Ruppe
You could make it work like this: auto slice3 = array[ slice1.length + (slice1.ptr - array.ptr) .. (slice2.ptr - array.ptr)]; Since the slices all start into array somewhere, subtracting the pointers gives their start index.

Re: genetically modified slices - is it possible?

2013-11-15 Thread Alexandr Druzhinin
15.11.2013 22:09, Adam D. Ruppe пишет: You could make it work like this: auto slice3 = array[ slice1.length + (slice1.ptr - array.ptr) .. (slice2.ptr - array.ptr)]; Since the slices all start into array somewhere, subtracting the point

Re: genetically modified slices - is it possible?

2013-11-15 Thread bearophile
Alexandr Druzhinin: I'd like to get slice that's consist of begining one other slice and end of yet another slice (all slices belong to the same array of course). Is it possible? With iterators it's simple, but I can't manage do it with slices. http://dpaste.dzfl.pl/443cd4a1 A simple soluti

Re: genetically modified slices - is it possible?

2013-11-15 Thread Alexandr Druzhinin
15.11.2013 22:13, bearophile пишет: Alexandr Druzhinin: A simple solution is to keep two indexes, and use them to find the slices when you need them. I did it the first. But then I decided to make it more D-ish and stumbled upon the issue. Wasn't it wrong decision and would be better to stay w

Re: genetically modified slices - is it possible?

2013-11-15 Thread QAston
On Friday, 15 November 2013 at 15:12:23 UTC, Alexandr Druzhinin wrote: 15.11.2013 22:09, Adam D. Ruppe пишет: You could make it work like this: auto slice3 = array[ slice1.length + (slice1.ptr - array.ptr) .. (slice2.ptr - array.ptr)]; Si

Re: genetically modified slices - is it possible?

2013-11-16 Thread Jonathan M Davis
On Friday, November 15, 2013 22:21:03 Alexandr Druzhinin wrote: > 15.11.2013 22:13, bearophile пишет: > > Alexandr Druzhinin: > > > > A simple solution is to keep two indexes, and use them to find the > > slices when you need them. > > I did it the first. But then I decided to make it more D-ish

Re: genetically modified slices - is it possible?

2013-11-16 Thread Alexandr Druzhinin
16.11.2013 18:38, Jonathan M Davis пишет: Well, if you want to get a slice which refers to the same thing as that slice but includes elements which are in what is being sliced but which aren't in that slice, you can only get the slice that you want be reslicing whatever the slices came from. So,

Re: genetically modified slices - is it possible?

2013-11-16 Thread Ali Çehreli
On 11/15/2013 06:55 AM, Alexandr Druzhinin wrote: I'd like to get slice that's consist of begining one other slice and end of yet another slice (all slices belong to the same array of course). Is it possible? With iterators it's simple, but I can't manage do it with slices. http://dpaste.dzfl.pl/

Re: genetically modified slices - is it possible?

2013-11-16 Thread Jonathan M Davis
On Saturday, November 16, 2013 08:10:30 Ali Çehreli wrote: > On 11/15/2013 06:55 AM, Alexandr Druzhinin wrote: > > I'd like to get slice that's consist of begining one other slice and end > > of yet another slice (all slices belong to the same array of course). Is > > it possible? With iterators it