genetically modified slices - is it possible?

bearophile bearophileHUGS at lycos.com
Fri Nov 15 07:13:25 PST 2013


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 solution is to keep two indexes, and use them to find 
the slices when you need them.

If you want to keep only slices around, then the third slice 
could be computed from the other two slices using a small 
function written by you, using the .ptr pointer of the two slices 
and some pointer arithmetic, plus some run-time preconditions to 
assert at run-time they are from the same array.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list