Let assume I have multiple files (like "file1", "file2" and so on). I need to iterate them simultaneously with some logic. I have tried to create random access range of ranges, however, it behaves not as expected. Let "file1" is
```
1
2
3
4
```

Then this code
```d
File[] files;
foreach(filename; args[1 .. $])
{
    files ~= File(filename, "r");
}

auto ranges = files.map!(a => a.byLineCopy);

writeln(ranges[0].front);
writeln(ranges[0].front);
writeln(ranges[0].front);
```
produces
```
1
2
3
```
Even despite I'm using `byLineCopy`.

However, this code
```d
File[] files;
foreach(filename; args[1 .. $])
{
    files ~= File(filename, "r");
}

auto range = files[0].byLineCopy;

writeln(range.front);
writeln(range.front);
writeln(range.front);
```
produses
```
1
1
1
```
as expected.

What I'm doing wrong with `map`? Or is this a bug?

dmd v2.085.0

P.S. I know that I can call `dup` on `front` and I'm going to do so as workaround. However, I'm curious why current situation is taking place.

Reply via email to