RefRange

Lars T. Kyllingstad public at kyllingen.net
Wed Jun 13 23:29:43 PDT 2012


On Thursday, 14 June 2012 at 05:45:50 UTC, Jonathan M Davis wrote:
> On Thursday, June 14, 2012 07:35:35 Lars T. Kyllingstad wrote:
>> However, someone pointed out here earlier that, since D uses 
>> the
>> dot operator for pointer dereferencing, a pointer to a range is
>> also a range.  It just isn't recognised as such by foreach.  So
>> if we could just fix foreach, and maybe add functions providing
>> range primitives for T[]* to std.array, I don't think we need a
>> separate RefRange.  Just take the address of the range when you
>> want to ensure it gets consumed.
>
> I don't think that that would work with save or opSlice though. 
> Granted, save
> and opSlice _can_ make it so that the range isn't consumed like 
> you'd like,
> depending on how the function that you're passing it to is 
> implemented, but
> having RefRange implement save and opSlice is still useful, and 
> is actually
> necessary if you want it to work as RandomAccessRange and the 
> like (since all
> of the more complex ranges are forward ranges). So, if that 
> won't work with a
> pointer (and I don't think that it will, since the type would 
> be completely
> wrong), then you'd still need a type like RefRange.

Ah, that's true, of course.  Indexing and slicing would be a 
disaster if one tried to do it with a pointer to a range. :)  
Then we should definitely have a RefRange.  I actually suggested 
the very same thing on the Phobos ML myself once, but Andrei 
argued it would be better to define a more general Ref type, 
which works with all kinds of types, and not just ranges.  
Personally, I would be happy with something just for ranges.

-Lars



More information about the Digitalmars-d mailing list