On Sunday, March 24, 2013 13:55:26 Manu wrote:
> I'd like to clarify some conflicts I've encountered.
> 
> TDPL talks about ranges, it mentions random access ranges requiring these
> functions:
> 
>   T at(int i)
>   Range slice(int x, int y)

This is not used by Phobos. I don't know why TDPL uses those. They are not 
supported at all and AFAIK never have been.

> Also, forward ranges require:
> 
>   Range save()
> 
> But there is also this function:
> 
>   Range opSlice()
> 
> With no args, handles the syntax 'range[]'. save() and opSlice() with no
> args would appear to be identical.
> Why have both? Which will be used in which cases?

Range opSlice()

is never used by ranges. It's only used by containers when you want to get a 
range for them.

If you want to know exactly which functions are supported by ranges, and the 
documentation isn't clear enough, just look at the definitions for the range 
traits in std.range - isInputRange, isForwardRange, etc. They specify exactly 
what a type must do to qualify as each type of range.

- Jonathan M Davis

Reply via email to