Printing a range of ranges drains them
Salih Dincer
salihdb at hotmail.com
Mon May 27 05:44:22 UTC 2024
On Monday, 27 May 2024 at 00:25:42 UTC, Steven Schveighoffer
wrote:
> So, does anyone expect this behavior? If so, can you explain
> why you think this is intentionally designed this way?
>
I think everything is as it should be. Because each element in
mdarr is a copy of each other. It will appear blank unless you
rewind. You can see the situation with the reward() function:
```d
//...
auto a = R(arr.ptr, arr.length);
auto arrs = [ a, a, a ];
void reward(R[] r)
{
foreach(i,ref e; r)
{
++i;
foreach(_; 0..i)
{
--e.ptr;
++e.len;
}
}
}
writeln(arrs); // [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
reward(arrs);
writeln(arrs); // [[3], [2, 3], [1, 2, 3]]
}
```
SDB at 79
More information about the Digitalmars-d
mailing list