On 12/02/2017 3:41 AM, error wrote:
I'm making a serializer that has a variadic write method that takes
arbitrary params
and serializes them;  I want to do the same thing with a read method (
pass in your
params by ref, and it populates them with data ) -  however, I run into
a compiler
error - "cannot be ref" in the foreach statement...  Anyone know a
workaround for this?  Is this a bug, or by design?

Simplified example:

void populateVars(T...)(T vars){
  // Generates "cannot be ref" compiler error:
  foreach(ref v; vars){
    // Populate v with some data here...
  }
}

Try:

foreach(i, v; vars) {
        vars[i] = ...;
}

Reply via email to