The Phobos Put

Salih Dincer salihdb at hotmail.com
Thu Mar 30 03:01:38 UTC 2023


On Wednesday, 29 March 2023 at 20:50:04 UTC, Steven Schveighoffer 
wrote:
> On 3/29/23 4:29 PM, ag0aep6g wrote:
>
>> But regardless of Salih's exact intent, the broader point is: 
>> a non-ref overload could be added to Phobos. And that would 
>> enable `a[1..$-1].phobos_put([2, 3])`. Which is what he asked 
>> about originally.
>
> I think the idea of requiring ref output ranges is that you can 
> then let the range keep track of its output state.

So why not copying the range to a static array?  The error during 
compilation of the code is as follows:

> onlineapp.d(6): Error: none of the overloads of template 
> `std.algorithm.mutation.copy` are callable using argument types 
> `!()(int[], int[8])`
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/mutation.d(367):        Candidate is: `copy(SourceRange, TargetRange)(SourceRange source, TargetRange target)`
   with `SourceRange = int[],
        TargetRange = int[8]`
   must satisfy the following constraint:
`       isOutputRange!(TargetRange, ElementType!SourceRange)`

```d
import std.algorithm.mutation : copy;
void main()
{
   int[8] buf;
   auto dig = [1, 2, 3, 4];
   auto rem = dig.copy(buf);
   assert(rem.length == 4);
}

```

Looks like 'copy' has the same overload issue.

SDB at 79



More information about the Digitalmars-d-learn mailing list