How to walk over two arrays by ref in beautyfull way?

vitalfadeev vital.fadeev at gmail.com
Mon Jun 10 07:45:42 UTC 2019


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();
>     }
>
> What is the best way for speed and beautyfull D code?
Detailed:

      import std.range : zip;

      struct Result {
          byte[] set;
      }
      Result result;

      alias Callback = bool delegate();
      Callback[] checkers;


      foreach(checker, ref r; zip(checkers, result.set)) {
         r = checker();
      }



More information about the Digitalmars-d-learn mailing list