How to use ranges?

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 23 03:38:51 PDT 2015


On 8/23/2015 10:17 PM, Doolan wrote:
> I keep running into areas of my code where it looks like I'd benefit
> from using ranges, and then I try to do some range stuff and my compiler
> tells me I'm using the wrong types, or there's this problem, or that
> problem... so I'm scared off and I just figure ways to work around using
> ranges.
>
> I've tried reading the documentation, but for a language priding itself
> on being readable and nice to look at, it really should have less
> complicated docs:
>
> auto tee(Flag!"pipeOnPop" pipeOnPop = Yes.pipeOnPop, R1, R2)(R1
> inputRange, R2 outputRange) if (isInputRange!R1 && isOutputRange!(R2,
> ElementType!R1));
> auto tee(alias fun, Flag!"pipeOnPop" pipeOnPop = Yes.pipeOnPop, R1)(R1
> inputRange) if (is(typeof(fun) == void) || isSomeFunction!fun);
>
> (That's fine as secondary information, but this is the heading for this
> function...)
>
> And the use of auto everywhere makes it really hard to tell what types I
> should be using for anything. My compiler talks about RangeT!(whatever)
> but you try to use RangeT!(whatever) and you find out RangeT is private...
>
> I don't mean to complain so hard, I obviously like D enough to want to
> use it, just the current amount/layout of documentation can be
> frustrating at times.
>
> Can someone give me a short summary of how to use ranges? And how do
> they relate to slices? That line is really blurry...

Have a read of: 
https://github.com/rikkimax/twp-d/blob/master/manuscript/content/idioms/ranges.md

Let me know what you think :)


More information about the Digitalmars-d-learn mailing list