usage of ref foreach with variadic functions fails with "cannot be ref"
error via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Feb 12 03:25:30 PST 2017
On Sunday, 12 February 2017 at 03:34:19 UTC, Michael Coulombe
wrote:
> Do you have a complete code example that gives your error? I
> can't reproduce it (DMD v2.073.0):
>
> int foo(T...)(T vars) {
> int i = 0;
> foreach(ref v ; vars) {
> v = 5;
> i += v;
> }
> return i;
> }
> void bar(T...)(ref T vars) {
> foreach(ref v ; vars) {
> v = 3;
> }
> }
> void main() {
> import std.stdio;
> int x = 7;
> bar(x);
> writeln(foo(4,x,8.2)); // 15, no errors
> }
Oh... That's really strange; I've updated my code to use non
indexed foreach, and it's now building without the error... I
have absolutely no idea what caused the error to occur. I've
also tried reverting to earlier versions of the project, and I
can't recreate the issue. If it occurs again, I'll snapshot the
project and try to make a repeatable set up.
More information about the Digitalmars-d-learn
mailing list