Need help how to get started with D ranges

Uranuz neuranuz at gmail.com
Mon Mar 24 08:00:30 PDT 2014


I have another question. For example I have some range with input 
data (for example some array). I using method popFront() to 
iterate to next element. Then with property front I check element 
if it has some value. Then I *save* it. But how could I get 
position of this derived range in original range without 
overhead. As I see it is only possible via additional variable 
that will keep this position. In this case I can't understand 
what is the benefit of range over iterators or simply iterating 
using some integral index. I should admit that I haven't used 
iterators a lot in C++ so I don't know all of it's possibilities/ 
advantages. It's why I asking.

In my algorithms for parsing some strings I often save positions 
of beginings of some tokens in order to take a slice and put it 
into some buffer. But for opearting with them in terms of ranges 
I need to have RandomAccessRange, because (as far as I 
understand) only it have ability to take a slice. But with input 
I will need to operate (save parsed data) element-wise. And this 
will realocate and slow execution. What is preferable startegy 
opearating with ranges that will be flexible and productive?


More information about the Digitalmars-d-learn mailing list