usage of ref foreach with variadic functions fails with "cannot be ref"
error via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Feb 11 06:41:55 PST 2017
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...
}
}
More information about the Digitalmars-d-learn
mailing list