How to walk over two arrays by ref in beautyfull way?
Anonymouse
zorael at gmail.com
Mon Jun 10 08:51:34 UTC 2019
On Monday, 10 June 2019 at 08:02:18 UTC, vitalfadeev wrote:
> On Monday, 10 June 2019 at 07:45:42 UTC, vitalfadeev wrote:
>> On Monday, 10 June 2019 at 07:41:40 UTC, vitalfadeev wrote:
>>> How to?
>>>
>>> I plan scan First array with checkers:
>>> [checker, checker, checker]
>>>
>>> ...and store result to Second array:
>>> [0, 0, 1]
>>>
>>> In next code 'r' not reference. But expected ref.
>>>
>>> import std.range : zip;
>>>
>>> foreach(checker, ref r; zip(checkers, result.set)) {
>>> r = checker();
>>> }
Replace zip with lockstep and your example works.
"zip is similar to lockstep, but lockstep doesn't bundle its
elements and uses the opApply protocol. lockstep allows reference
access to the elements in foreach iterations."
https://dlang.org/library/std/range/zip.html
"Function lockstep
Iterate multiple ranges in lockstep using a foreach loop. In
contrast to zip it allows reference access to its elements."
https://dlang.org/library/std/range/lockstep.html
More information about the Digitalmars-d-learn
mailing list