Associative Array c'tor

Bahman Movaqar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 11 06:48:49 PDT 2016


I'm processing a list of structs (MySt) with `reduce` to produce an
associate array of type `MySt[][string]`.
Right now I'm using the following (slimmed down) code:

    MySt[][string] result;
    return reduce!(
      function MySt[][string](MySt[][string] acc, MySt val) {
        // do something with acc
        return acc;
      }
    )(result, inputList);

I was wondering if I could remove the empty declaration line (line 1);
for example:

    return reduce!(
      function MySt[][string](MySt[][string] acc, MySt val) {
        // do something with acc
        return acc;
      }
    )(new MySt[][string](), inputList);

Obviously, this fails with the error message: "cannot pass type string
as a function argument".

I very much would like to avoid empty declaration lines like that of
`result`.  Is there anyway you folks would suggest?

Thanks in advance,
--
Bahman


More information about the Digitalmars-d-learn mailing list