rotate left an array

Paul Backus snarwin at gmail.com
Tue Oct 4 00:50:22 UTC 2022


On Tuesday, 4 October 2022 at 00:38:25 UTC, Ali Çehreli wrote:
> 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.

AFAIK there is no generic way to perform a deep copy of an 
arbitrary value in D. You could write a function to do it for all 
built-in types, but you might still run into trouble with 
user-defined types (e.g., how do you deep-copy a RefCounted!T 
without any knowledge of its specific semantics?).

I guess you could use a hybrid approach; e.g.,

     static if (isDeepCopyable!(ElementType!R))
         auto fr = range.front.deepCopy;
     else
         auto fr = range.front.save;

This would make it possible to accommodate some pure input ranges 
(including File.byLine), but would still require a forward range 
in the general case.


More information about the Digitalmars-d-learn mailing list