RefRange

David d at dav1d.de
Sun Aug 26 14:21:34 PDT 2012


Am 26.08.2012 20:07, schrieb Jonathan M Davis:
> On Sunday, August 26, 2012 10:17:13 Jonathan M Davis wrote:
>> On Sunday, August 26, 2012 17:41:45 David wrote:
>>> It's a RefRange, but not completly ... Can somebody explain me that
>>> behaviour?
>>>
>>> http://dpaste.dzfl.pl/643de2a3
>>
>> refRange simply returns the original range if it's an input range rather
>> than a forward range, since normally, when you have an input range, it
>> isn't a value type, and there's no way to copy it, so operating on one
>> reference of it is already the same as operating on all of them, making
>> RefRange pointless.
>>
>> However, you've done the odd thing of declaring a value type input range. I
>> don't know why that would ever be done except through ignorance of how
>> ranges work. So, refRange is actually returning a copy in your case, which
>> is why you're having problems.
>
> Though the fact that you ran into this issue may indicate that having refRange
> return the original if it isn't a forward range was a bad decision. I don't
> know. In the normal case, it's definitely better, because it avoids an
> unnecessary wrapper, but obviously, people can make mistakes. You should still
> be able use RefRange with an input range though, as long as you use it
> directly.
>
> auto wrapped = RefRange!TestRange(&orig);
>
> But it would be better IMHO to just fix it so that your range is a forward
> range, since there's no reason for it not to be.
>
> - Jonathan M Davis
>

Ranges died another time for me. This refRange copy thingy cost me lots 
of time, then I tried to implement a .save method, which uhm, just 
didn't work together with RefRange (isForwardRange!T succeeded, but 
isForwardRange!(RefRange!T) failed).

Anyways, thanks for your explanations!


More information about the Digitalmars-d-learn mailing list