On 10/3/22 17:00, Paul Backus wrote:
> On Monday, 3 October 2022 at 21:06:36 UTC, Ali Çehreli wrote:
>> On 10/3/22 13:48, Andrey Zherikov wrote:
>>> a "rotated view".
>>
>> Without indexes:
>>
>> import std.range : empty;
>>
>> auto rotatedView(R)(R range)
>> in (!range.empty)
>> {
>>     import std.range : chain, front, only, popFront;
>>     const fr = range.front;
>>     range.popFront();
>>     return chain(range, only(fr));
>> }
>
> Tiny nitpick: this should use
>
>      const fr = range.save.front;
>
> ...to ensure that `fr` is not invaliated or overwritten by the
> subsequent call to range.popFront (e.g., think of File.byLine here).

Good catch but I think what we want is a copy of the front element, at least for InputRanges (.save does not work for File.byLine :/).

What is the generic way of copying an element? I wonder whether we have to use isSomeString to take care of all element types.

Ali


Reply via email to